布尔变量javascript

时间:2013-09-18 09:24:04

标签: javascript boolean var

你需要帮助解决“var破坏性变量”的问题。我需要回答一下  “Y或N”。并在if

中放入第3个条件
     <script type="text/javascript">

     var examResult;
     var attendance;
     var disruptive;

     examResult=parseInt(prompt("Enter Exam result:",""));
     attendance=parseInt(prompt("Enter Attendance:",""));
     disruptive=prompt("Disruptive Y/N:",""); 
     if((examResult>=40) && (attendance>=75) &&("disruptive))
     {
 document.write("You have passed");
     }
     else
     {
document.write("You have failed")
     }

     </script>

3 个答案:

答案 0 :(得分:0)

试试这个

 var examResult;
 var attendance;
 var disruptive;

 examResult=parseInt(prompt("Enter Exam result:",""));
 attendance=parseInt(prompt("Enter Attendance:",""));
 disruptive=prompt("Disruptive Y/N:",""); 
 if((examResult>=40) && (attendance>=75) &&(disruptive=="Y"))
 {
    concole.log("You have passed");
 }
 else
 {
    concole.log("You have failed")
 }

DEMO

答案 1 :(得分:0)

你的if语句有错误。删除“”(双引号),然后尝试

答案 2 :(得分:0)

在if语句之前添加此内容

 disruptiveString=prompt("Disruptive Y/N:","");
 if (disruptiveString == "Y"){
        disruptive = true;
    }
else{
    disruptive = false;
}

同样如@Java Buddy所述,删除“在你的陈述中