SCSS

by cooper081

JavaScript

function getRandom(x) {
          return Math.floor(Math.random() * x + 1);
        };


        function getNum() {
          let ansewer = [];
          let check = [];


          let n = 0;

          for (i = 0; i <= 7; i++) {
            let n = getRandom(31);
            if (ansewer.indexOf(n) > 0) {
              i--;
              continue;
            } else {
              ansewer.push(n);
            };
          };

          ansewer.sort((a, b) => {
            return a - b;
          });

					//檢查是否組數相減有小於等於 -6 的
          for (let i = 0; i < ansewer.length; i++) {
            check.push(ansewer[i] - ansewer[i + 1])
          }

          if (check.find((el) => el <= -6)) {
            location.reload()
          }

          console.log(ansewer, check);
          return ansewer;
        };

        getNum()