多重判断if..else嵌套语句

要在多组语句中选择一组来执行,使用if..else嵌套语句,语法如下:

1 if(条件1)
2 { 条件1成立时执行的代码}
3 else  if(条件2)
4 { 条件2成立时执行的代码}
5 ...
6 else  if(条件n)
7 { 条件n成立时执行的代码}
8 else
9 { 条件1、2至n不成立时执行的代码}

举例:假设数学考试,小明考了86分,给他做个评价,60分以下的不及格,60(包含60分)-75分为良好,75(包含75分)-85分为很好,85(包含85分)-100优秀。

 1 <!DOCTYPE >
 2 <html>
 3     <head>
 4         <title>if..else嵌套语句</title>
 5         <meta charset="utf-8">
 6         <script>
 7         var myscore=98;
 8         if(myscore<60){
 9             document.write('60分以下成绩不及格')
10         }else if(myscore<75)
11         {
12             document.write('60(包含60分)-75分为良好')
13         }else if(myscore<85)
14         {
15             document.write('75(包含75分)-85分为很好')
16         }else
17         {
18             document.write('85(包含85分)-100优秀。')
19         }
20         </script>
21     </head>
22     <body>
23     </body>
24 </html>
posted @ 2020-04-15 23:01  鬼牛阿飞  阅读(10747)  评论(0编辑  收藏  举报