流程控制

1.1 条件语句 分支结构

单向分支

if (条件表达式) {
	code...
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>if流程控制双向分支,if..else</title>
    <style type="text/css">
        div {
            width: 100px;
            height: 50px;
            border: 1px solid gray;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <h1>成绩查询</h1>
    <hr>
    <h2>输入你的成绩:</h2>
    <input type="number" >
    <button onclick="makeScore()">查询</button>
    <div id='res'></div>

    <!--第一种:if..else双向分支-->
    <script type="text/javascript">
        function makeScore() {
            //之前的写法3行:
            // var scoreNum =document.getElementById('score')
            // var Num = scoreNum.value;
            // Num = Number(Num)

            //精简一行写法如下:
            var score=Number(document.getElementById('score').value)

            if (score > 60) {
                var resContent = `成绩为:${score},恭喜及格了`;
            }else {
                var resContent = `成绩为:${score},不及格继续努力哦`
            }

            document.getElementById('res').innerHTML = resContent;

        }
        

    </script>
</body>
</html>

 



相关文章:

  • 2021-06-10
  • 2022-01-14
  • 2022-01-21
  • 2020-07-26
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
猜你喜欢
  • 2021-07-09
  • 2022-12-23
  • 2022-03-03
  • 2022-12-23
  • 2020-05-26
  • 2021-04-02
  • 2022-01-12
相关资源
相似解决方案