Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-19-2012, 12:10 PM   PM User | #1
Entity_
New Coder

 
Join Date: Dec 2012
Location: Ingerlund
Posts: 62
Thanks: 8
Thanked 4 Times in 4 Posts
Entity_ is an unknown quantity at this point
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!
Entity_ is offline   Reply With Quote
Old 12-19-2012, 12:51 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 12-19-2012 at 01:01 PM..
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
Entity_ (12-19-2012)
Old 12-19-2012, 01:26 PM   PM User | #3
Entity_
New Coder

 
Join Date: Dec 2012
Location: Ingerlund
Posts: 62
Thanks: 8
Thanked 4 Times in 4 Posts
Entity_ is an unknown quantity at this point
DAMMIT! Knew it would be something simple! Thanks very much!
Entity_ is offline   Reply With Quote
Old 12-19-2012, 09:52 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by Philip M View Post
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>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-19-2012, 10:02 PM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by Old Pedant View Post
Okay, why is that funny?

<grin style="MONSTROUS!"> Who but a Brit would care? </grin>
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.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 12-19-2012, 10:34 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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?)
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-20-2012, 01:24 AM   PM User | #7
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,462
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by Old Pedant View Post
(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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 12-20-2012, 02:32 AM   PM User | #8
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,468
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
simplified :

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

isEven(2);
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:30 AM.


Advertisement
Log in to turn off these ads.