CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Simple statement to find it number is odd or even (http://www.codingforums.com/showthread.php?t=284401)

Entity_ 12-19-2012 12:10 PM

Simple statement to find it number is odd or even
 
Here it is:

Code:

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

isEven(2);


This seems to return false, but I have no idea why. AFAIK if you put in an even number, it should hit the if statement, come up with no remainder and so return true! Sadly it returns false every time. I know this is very simple stuff guys but please don't make fun of me:( I learn better when I can ask stupid questions and you only have to ask them once!

Philip M 12-19-2012 12:51 PM

if(isEven%2===0){

should be

if(number%2===0){

You are testing whether the number is odd/even, not the function!

It is dangerous to use number as the name of a variable - too easily confused with the Javascript method Number().

Quizmaster: In 1917 King George V changed the name of the British royal house from Saxe-Coburg Gotha to what?
Contestant: Tudor.

Entity_ 12-19-2012 01:26 PM

DAMMIT! Knew it would be something simple! Thanks very much!

Old Pedant 12-19-2012 09:52 PM

Quote:

Originally Posted by Philip M (Post 1301004)
Quizmaster: In 1917 King George V changed the name of the British royal house from Saxe-Coburg Gotha to what?
Contestant: Tudor.

Okay, why is that funny?

<grin style="MONSTROUS!"> Who but a Brit would care? </grin>
:o:o:o

Philip M 12-19-2012 10:02 PM

Quote:

Originally Posted by Old Pedant (Post 1301131)
Okay, why is that funny?

<grin style="MONSTROUS!"> Who but a Brit would care? </grin>
:o:o:o

Because the House of Tudor was the monarchy in the 16th century. I would have thought that as an educated person you knew that, actually. The correct answer is, of course, Windsor.

Old Pedant 12-19-2012 10:34 PM

Oh, come on, Philip! I knew all that! Just having fun.

I even knew that the name was originally "Tewdwr" and/or "Tudur".

(Have to admit I don't know where George V came up with the name "Windsor" other than, presumably, from Windsor Castle. Did it ever have any actual royal associations before that?)

felgall 12-20-2012 01:24 AM

Quote:

Originally Posted by Old Pedant (Post 1301143)
(Have to admit I don't know where George V came up with the name "Windsor" other than, presumably, from Windsor Castle. Did it ever have any actual royal associations before that?)

My understanding is that it was from Windsor castle. The name schange was needed in a hurry to get rid of the German surname that Victoria acquired for the family when she married Albert - given that George had just gone to war with his German cousin.

rnd me 12-20-2012 02:32 AM

simplified :

Code:

function isEven (n) {
          return ! (n % 2);
}

isEven(2);



All times are GMT +1. The time now is 10:48 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.