Quotes help make search much faster. Example: "Practice Makes Perfect"

Monday, December 10, 2012

Codeyear: Revisiting guessNumber, Part 1


//sample solution


function guessNumber(number, clue) {
  // Prompt the user for a number using the string value of clue
  guess = prompt(clue);
  // Convert their guess to a number using +
  guess = +guess;
 
  while (guess !== number) {
    if (guess < number) {
      guess = prompt("Too low. Guess again.");
    }
    else if (guess > number) {
      guess = prompt("Too high. Guess again.");
    }
    guess = +guess;
  }
 
  console.log("You got it! The number was " + number);
}
guessNumber(8,"My number is between 7 and 11. Can you guess it?")

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts