我試圖創建一個alert
詢問用戶電子郵件,如果它與存儲的變量兼容,那麼將出現一個警報,並記錄!消息,但循環不適用於我的代碼if
和else
但只有一次。if和else語句在while循環中將不起作用
//working code
function validation(str) {
var str = prompt("Please Enter your email");
var email = "[email protected]";
if (str === email) {
return alert("Welcome back, Logged Successfully!" + " your email is " + str);
} else {
return alert("Your Email is incorrect, Please Try again");
}
}
validation();
//Loop Code
function validation(str) {
var str = prompt("Please Enter your email");
var email = "[email protected]";
while (str !== email) {
if (str === email) {
return alert("Welcome back, Logged Successfully!" + " your email is " + str);
} else {
return alert("Your Email is incorrect, Please Try again");
}
str++;
}
}
validation();
調用'海峽=提示( 「請輸入您的電子郵件」);''你聲明else'內。那麼'str ++'是做什麼的? – Walk
你想用while循環完成什麼?什麼是'str ++'? – Kokodoko
把提示放進去,同時使用無限循環while(1),並在電子郵件匹配時打破 – Niladri