【程序5】 题目:利用条件运算符的嵌套来完成此题:学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示。 1.程序分析:(a>b)?a:b这是条件运算符的基本例子。

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();
文章来自:http://www.cnblogs.com/sifangku/p/7144772.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3