使用if语句的意外标记“{”

时间:2016-03-07 20:16:06

标签: javascript

我不知道为什么,但每次运行此代码段时,我都会在初始if语句中不断出现意外令牌“{”的语法错误。知道为什么吗?

var place = prompt("Go ahead and pick a place, it could be anywhere.");

if ((!isNaN(place)) {
    place = prompt("That doesn\'t sound like a place. Try again. Pick a place", "");
} else if (place == "" || place == null) {
    place = alert("You\'re no fun. Come back when you want an adventure");
} else {
    place = alert("So out of all the places you picked, you picked " + place + "?");
}

1 个答案:

答案 0 :(得分:2)

这是因为你还需要再关闭一次')。这样:

if ((!isNaN(place)) 

应该是

if ((!isNaN(place))) { //one for isNaN, one for (!..) and one more for if()
相关问题