Code Hs is it even

ysiyez16

Commendable
alue 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!

this is what code hs wants and this is what I did
function start(){
isEven(0);
}

function isEven(x){
var even = x % 2 == 0;

var odd = x % 2 == 1;

if(x = even){
var result = println("Even. ");
return result;
}
if(x = odd){
var reeult = println("Odd. ");
return reeult;
}
}

and code hs says that it is incorrect. I'm working on it for two weeks and I couldn't finish it. Someone please help !

Solution
Where the code that ask for user enter a number?

and your isEven is not returning true or false

Why are you comparing x with even or odd?

rgd1101

Don't
Moderator
Where the code that ask for user enter a number?

and your isEven is not returning true or false

Why are you comparing x with even or odd?

ysiyez16

Commendable
How can I return true or false ?

rgd1101

Don't
Moderator

return the result of if it even or odd, a boolean. Did you miss a few class? what programming language is this?

Replies
2
Views
1K
Replies
0
Views
169
Replies
0
Views
2K
Replies
0
Views
22K
Replies
6
Views
9K