我想編寫一個簡單的表單,詢問以下輸入:爲什麼這個表單代碼不起作用?這似乎是合乎邏輯
情緒,年齡和性別
不要緊,什麼我把心情提示。它總是出現積極的。對於這個年齡段,如果他們年齡在18歲以下,我希望標籤關閉。對於性別而言,它與情緒提示一樣。任何幫助,將不勝感激。
var userMood = prompt("Hey! How's it going?");
\t if (userMood = "good" || "Good") {
\t \t alert("Awesome! We just need you to fill out a form for security reasons.");
\t } else if (userMood != "good" || "Good") {
\t \t alert("Oh, I'm sorry to hear that... We just need you to fill out a form for security reasons.");
}
var userAge = prompt("What is your current age?");
\t if (userAge >= "18") {
\t \t alert("Great! You are the sufficient age to enter this webpage!");
\t \t userAge = true;
\t } else if (userAge <= "17"){
\t \t alert("Sorry, you are too young to view this content...");
\t \t window.close();
}
var userGender = prompt ("What is your gender?");
\t if (userGender = "male" || "Male" || "female" || "Female"){
\t \t alert("Great! You're human!");
\t \t userGender = true;
\t } else {
\t \t alert("The webpage has perdicted non-human cyber activity, you can no longer continue.");
\t \t window.close();
\t }
也許你也想考慮加入其他變化「好」,如'gooD'或'GooD'等。我想總共需要16個樣本。除非有人編碼以更簡單的方式做到這一點。 –
一切正常,我喜歡你添加的空格,但不知何故,如果用戶年齡無效,程序仍然不會關閉窗口?幫助,將不勝感激 –
好的,請稍候。我將編輯。我添加了'window.close();'if userAge <0'。 –