简单的循环卡住了

时间:2017-11-17 22:00:40

标签: javascript

我正在尝试reddits每日程序员挑战之一,出于某种原因,我看似正确而简单的代码似乎陷入困境。  Here is a link to the challenge I am doing

function play() {
  var start = document.getElementById("userInput").value;
  var number = parseInt(start);
  if (Number.isInteger(number) === true) {
    while (number != 1) {
      if (number % 3 === 0) {
        number / 3;
        document.getElementById("answer").append(number + "/3");
      } else if ((number - 1) % 3 === 0) {
        number = number - 1;
        document.getElementById("answer").append(number + "-1");
      } else if ((number + 1) % 3 === 0) {
        number = number + 1;
        document.getElementById("answer").append(number + "+1");

      } else {
        document.getElementById("answer").append(number + "done");
      }
    }
  } else {
    document.getElementById("answer").innerHTML = "Please enter a WHOLE NUMBER";
  }
}

0 个答案:

没有答案