-1

嗨,在如何处理“ var 破坏性变量”方面需要帮助。我需要在“Y 或 N”中回答。并在 if 中放入第三个条件

     <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>
4

3 回答 3

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")
 }

演示

于 2013-09-18T09:27:31.137 回答
0

您的 if 语句有错误。删除 '"' (双引号),然后尝试

于 2013-09-18T09:28:58.440 回答
0

在你的 if 语句之前添加这个

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

同样正如@Java Buddy 所指出的,删除声明中的 "

于 2013-09-18T09:30:10.340 回答