1. if/else


#1


https://www.codecademy.com/courses/javascript-beginner-en-qDwp0/0/1?curriculum_id=506324b3a7dffd00020bf661#


It says when 3 is inputed it comes out as true.


var isEven = function(number) {
    if(isEven % 2 = 0){
        return true;
    } else {
        return false;
    }
};


#2

in javascript, a single equal sing means assign, not is equal


#3

Your function is ignoring its argument, I doubt it'll be able to accurately tell whether the argument is odd or even without looking at it


#4

Ok now I put
var isEven = function(number) {
if (isEven % 2 === 0){
return true;
} else {
return false;
}// Your code goes here!

};
but when two is input it returns false


#5

so know you check if your function divided by two has a remainder of zero, does that make sense?


#6

"isEven" is the name of your function. "number" is the name of the variable you want to check if it's even or odd. So "number" is the variable that should be inside the if condition


#7

your error is in this step>> if(isEven % 2 = 0)
1-isEven is Boolean function equals to true or false what you did like :
if(true % 2 = 0) or if(false % 2 = 0)
2-you use this function to check any number you send, so your function should receive it and you should send it when you call this function
like this:
//i changed number to num in my code
var isEven = function(num) {
// Your code goes here!
if(num%2 === 0)
{return true;}
else
{return false;}
};
//the number that you will check
var num = Math.floor(Math.random()*100);
console.log(num);
//calling your function
isEven(num);
//you can send a specific number instead Math.floor(Math.random()*100)like
/*
isEven(5);
*/


#8

A post was split to a new topic: 1. if/else


#9

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