Jump to content

Java script help

Go to solution Solved by Mr_KoKa,
var isEven = function(number) {
 if(number % 2 === 0){
     return true
 }
 else if (isNaN(isEven)){
  return "This ain't a numbah" 
  // This return probably evaluates to true as after you check if number % 2 === 0, if is not then you check isNaN(isEven) and in fact
  // isEven is not a number, it is a function, you probably meant to check isNaN(number), but even though, I would check it
  // before I do any number operations on variable.
 }
 else{
  return false 
 }
};

 

I'm taking an online course to learn java script, however I seem to be stuck on a certain lesson. The point of this lesson is to see if a number is divisible by two. Each time I try to submit my code it says that the number three is divisible by two. The only logic I could think of that would prove this is since 3 / 2 = 0.5 the code thinks that 0.5 is the same as 0. There's no way to skip this lesson so I have to figure this out to move on. What can I change about my code to fix this issue?

 

My code:

/*var isEven = function(number) {
 // Your code goes here!
 if(number % 2 === 0){
     return true
 }
 else if (isNaN(isEven)){
  return "This ain't a numbah"
 }
 else{
  return false 
 }
};*/

Also, I don't have to call the function or this lesson so that's not the problem but any help is appreciated.

Link to comment
https://linustechtips.com/topic/641996-java-script-help/
Share on other sites

Link to post
Share on other sites

var isEven = function(number) {
 if(number % 2 === 0){
     return true
 }
 else if (isNaN(isEven)){
  return "This ain't a numbah" 
  // This return probably evaluates to true as after you check if number % 2 === 0, if is not then you check isNaN(isEven) and in fact
  // isEven is not a number, it is a function, you probably meant to check isNaN(number), but even though, I would check it
  // before I do any number operations on variable.
 }
 else{
  return false 
 }
};

 

Link to comment
https://linustechtips.com/topic/641996-java-script-help/#findComment-8273124
Share on other sites

Link to post
Share on other sites

4 minutes ago, Mr_KoKa said:

var isEven = function(number) {
 if(number % 2 === 0){
     return true
 }
 else if (isNaN(isEven)){
  return "This ain't a numbah" 
  // This return probably evaluates to true as after you check if number % 2 === 0, if is not then you check isNaN(isEven) and in fact
  // isEven is not a number, it is a function, you probably meant to check isNaN(number), but even though, I would check it
  // before I do any number operations on variable.
 }
 else{
  return false 
 }
};

 

Thank you

Link to comment
https://linustechtips.com/topic/641996-java-script-help/#findComment-8273143
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×