if…else语句相对比较多,但是容易理解

 1     var scroe = window.prompt("请输入1-100之间的数")
 2     scroe = parseInt(scrol);
 3     if (scroe>=1 && scroe<=100) {
 4         if (scroe>=90) {
 5             document.write("您的分数是" + scroe + "分 ,为A" )
 6         } else if(scroe>=60 && scrol<=89) {
 7             document.write("您的分数是" + scroe + "分 ,为B" )
 8         } else if(scroe < 60) {
 9             document.write("您的分数是" + scroe + "分 ,为C" )
10         }
11     } else {
12         document.write("请重新输入")
13     }

 


三目运算符,代码简单,却不易理解
话不多说,直接上代码

function text() {
     var j = score>=90?"A":(score<60?"C":"B");
     document.write(j);
}
text();
posted on 2017-07-10 11:04  公子寒  阅读(722)  评论(0编辑  收藏  举报