[英]Can you tell me what is wrong with this javascript code?
//确定年龄是否大于等于13岁或是否已陪同
var age = prompt("How old are you")
var accompanied = prompt("Are you accompanied by an adult")
if (age >= 13 || accompanied == "Yes"){
console.log("you may see the movie")
}else{
console.log ("You can not see the movie")
检查下面的代码片段,
var age = Number(prompt("How old are you")); var accompanied = prompt("Are you accompanied by an adult"); if (age >= 13 || accompanied == "Yes"){ console.log("you may see the movie") }else{ console.log ("You can not see the movie") }
您的代码运行完美,但是您错过了一些分号;
,而忘记在else
语句的最后关闭大括号}
。
尽管代码不需要分号,但不使用分号就不应编写JavaScript代码:
var age = prompt("How old are you"); var accompanied = prompt("Are you accompanied by an adult"); if (age >= 13 || accompanied == "Yes") { console.log("you may see the movie"); } else { console.log("You can not see the movie"); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.