chunkydonuts21
chunkydonuts21

Reputation: 79

code stops looping

My code is not working properly. It is not continuing the loop. It is just showing that your value is low or high and stopping it there. Why doesn't it keep looping?

var target;
var count = 0;
var play;
var game;

function do_this() {
  var choose = (Math.floor(Math.random() * 100));
  target = choose + 1;
  while (true) {
    play = prompt("I am thinking of a no. between 1 and 100\n\n" + "enter the no.");
    game = parseInt(play);
    count = count + 1;
    if (isNaN(game)) {
      alert("Please enter integer value");
      return false;
    }
    if ((game < 1) || (game > 100)) {
      alert("Please enter the value between 1 and 100");
      return false;
    }
    if (game < choose) {
      alert("enter higher value");
      return false;
    }
    if (game > choose) {
      alert("enter lower value");
      return false;
    }
    alert("You are correct\n\n" + "you took" + count + "to guess the game");
    return true;
  }
}

do_this()

Upvotes: 0

Views: 47

Answers (1)

ASDFGerte
ASDFGerte

Reputation: 5195

You are using return false; when the value is higher or lower. Replace that with continue;

Upvotes: 1

Related Questions