05 if...else语句

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <script type="text/javascript">
         var distance = 10;
         var nowDistance = 5;
         if (nowDistance<distance) {
            console.log('自动驾驶')
         } else{
            console.log('人为驾驶')
         }

         var weather = 'rainy';
         if (weather === 'sunny') {
            console.log('天气非常棒')
         }
         else if (weather === 'rainy') {
            console.log('天气下雨了')
         }
         else if (weather === 'snowing') {
            console.log('天气下雪了')
         }
         else{
            alert('输入天气有错')
         }
    </script>
</body>
</html>
posted @ 2020-12-19 21:03  *!Walter!*  阅读(79)  评论(0编辑  收藏  举报