I am learning JavaScript and have decided to do a basic Switch piece of code. I am trying to make my prompts' inputs case-insensitive using the .toLowerCase. However, that isn't working:
document.getElementById("button").onclick=function(){
var question = prompt("How do you do");
switch(question) {
case "Great".toLowerCase:
alert("Excellent!");
break;
case "Good".toLowerCase:
var question_2 = prompt("Could it be better?");
if(question_2 == "yes") {
alert("Well lets hope tomorrow is better!")
}
else {
alert("Phew! You got me for a moment!")
}
break;
case "Bad".toLowerCase:
var q_3=prompt("What happened!");
if(q_3) {
alert("I hope tomorrow is better!");
}
else {
alert("I didn't quite get that..");
}
break;
default: alert("I didn't understand...");
}
}
Every time I insert text, correct or incorrect, I will always get "I didn't understand", which I believes that any input is wrong. E.g, if I insert into the 'question' prompt "great" or "Great" or even "GREAT", I will always get "I didn't understand" as an alert. Any help?
Aucun commentaire:
Enregistrer un commentaire