I need Help with if /else


#1

error:
" Looks like your function returns false when number = 2. Check
whether your code inside the if/else statement correctly returns true if
the number it receives is even."

Many thanks for your help.


var isEven = function(number) {
// Your code goes here!
var myNumber = prompt ("Enter a number");

if (myNumber %2 === 0 ) {
console.log ("even = " + myNumber);
return true;
} else {
console.log("odd = " + myNumber);
return false;
}
};


#2

var isEven = function(number) {
  // Your code goes here!
var myNumber = prompt ("Enter a number");

Well you ignore the user input via the number parameter and instead prompt the user to "Enter a number". So when a script runs your code with idk isEven(2) your function will prompt the script to enter a number which probably goes wrong and the 2 that was originally meant to be checked is ignored anyway. So if you want to test this by a user better do it like this:

var myNumber = prompt ("Enter a number");

//your function without this line

isEven(myNumber);

#3

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