语法错误意外标识符出了什么问题?

时间:2015-05-25 13:13:39

标签: javascript

confirm("are you ready to play")

var age = prompt("What's your age");

if(age is less than 13) {

    console.log("You are allowed to play but I take no responsibility")

} else {

    console.log("You will feel honored to play this game!")

}

为什么这是意外的标识符?

2 个答案:

答案 0 :(得分:3)

此:

if(age is less than 13) 

必须更改为

if(age < 13) 

is less than不是JavaScript的有效语法。

答案 1 :(得分:0)

这不是我们将逻辑从简单的英语转换为代码语言的方式......你使用的英语不是

而是使用编译器将理解的内容只需将其更改为以下语法

if(age < 13) 

你已经完成了