[英]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.