CodeHS JavaScript Help

luckyterrestrial

Estimable
Can someone help me with this problem?
Write a function called `isEven` that returns a boolean of whether or not a value is even or odd. The `isEven` function should not print anything out or return a number. It should only take in a number and return a boolean.

For example, if you made a call like

var isEvenNumber = isEven(4);
isEvenNumber should have the value true.

Once you’ve written this function, write a program that asks the user for integers and prints whether the number they entered is even or odd using your isEven function. You should let the user keep entering numbers until they enter the SENTINEL.

Here is a sample run of the program:

Enter a number: 5
Odd
Enter a number 42
Even
Enter a number: -6
Even
Enter a number: 0
Done!

rgd1101

Don't
Moderator
and the problem is? sound really simple, what do you have so far?

luckyterrestrial

Estimable

var SENTINEL = 0;

function start(){
isEven(4);
}

function isEven(x){
var even = x % 2 == 0;
return even;
}
Have this so far

luckyterrestrial

Estimable

I can't get it to print "Even" if its even and "Odd: if its odd.

rgd1101

Don't
Moderator
You call the function passing a 4, but you are not doing anything with the result

So, how would I?

Replies
3
Views
7K
Replies
1
Views
2K
Replies
2
Views
6K
Replies
7
Views
6K