JavaScript利用逢7过游戏理解while循环

逢7过游戏,打印1-100,遇到能被7整除或者带7的数字打印“过”代替

 <script>
 var n = 0
    while (n < 100) {
      n++
      // 判断n是否能被7整除或者十位是否包含7或者个位是否包含7
      var gw = n % 10
      var sw = parseInt(n / 10)
      if (n % 7 === 0 || sw === 7 || gw === 7) {
        console.log('过')
      // 如果满足条件,那么打印 过 并且下面的console也就不执行了
        continue;
      }
      console.log(n)
    }
  </script>
发布了62 篇原创文章 · 获赞 0 · 访问量 538

猜你喜欢

转载自blog.csdn.net/qq_43633053/article/details/105258421