12. Higher or Lower. Recursion in Javascript


#1

Please I don’t know what I am doing wrong. I am getting “Oops, try again. false”. Please help! https://www.codecademy.com/courses/javascript-lesson-205/2/3#

This is my code:

function guessNumber(number) {
// Prompt the user for a number
var guess = prompt(“Guess a number between 1 and 100”);

// Convert their guess to a number using +
guess = +guess;

// Define base case
if (guess === number) {
return console.log("You got it! The number was " + number);
} else {
console.log(“Please try again”);
}
// Define recursive case with a function call
guessNumber(number);
}

// Call the function guessNumber() with an integer for an argument
guessNumber(7);


#2

var guess = prompt(“Guess a number between 1 and 100”);

remove the var keyword.

Though it’s not your fault but the system checker doesn’t expect it.


#3

Thank You! It worked!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.