Why does this code pass and how can I properly use %modelo instead?


#1



my code surprisingly passes and I did not expect it to. How can I properly use %modelo instead?


var isEven=function(number) {
if(isEven=2){
isEven=true}
else if (isEven=1){
isEven=false}
};


#2

If you wanted to use the modulo, you would want to use something like

As far as why the code passes, I don't know. It was probably just a slip in the system. You're bound to find them here and there.


#3

Did you get the correct answer?
Here is my take on it, I don't claim that is true or correct, just an observation.

I think your conditional works because isEven = (equals) 2, which then it is assigned to be true (isEven=true) and then the same for the else if condition.

I hope this post doesn't provide confusion. Feel free to correct me if I'm wrong.

As far as using the modulo, this worked for me:
var isEven = function(number) {

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

I read in another post to use "number" because that is the input needed to determine if it is divisble by 2.

};

#4

I just let my initial code ride it out for that exercise... I'm gonna have to do some review after I get done with this section


#5

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