if / else语句不起作用?

时间:2013-09-04 03:49:52

标签: javascript if-statement

我是编码的新手,我无法弄清楚我做错了什么。每次我尝试编写if / else时,它都可以达到声明的程度,然后就不会起作用了。

这就是我写的:

alert("welcome to chloe's quiz show!")
var name = prompt("contestant, what is your name?")
var help = prompt("is this your first time playing? type 'yes' or 'no'.")
if (help === yes){
alert("the game is easy! all you have to do is type the letter that corresponds with  the correct answer. then press 'ok'.")
confirm("lets get started!")
}
else{
confirm("lets get started then!")
}

2 个答案:

答案 0 :(得分:6)

更改此行:

if (help === yes)

到此:

if (help == "yes")

由于yes不是变量。

答案 1 :(得分:3)

if (help === 'yes')

yes是一个字符串,必须引用