1. If / Else


#1

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

SyntaxError:Unexpected token 'else'
Line 8:Missing ";" before statement.
Expected an identifier and instead saw 'else' (Didn't appear in Codecademy labs).

Code listed here:

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


#2

if (number % 2); \ { <--- opening curly brace is missing


#3

Still the exact same problem.


#5

As @ramu.ausettygmail.co said you are missing an opening brace.
In an if statement you should not have a semi-colon after the condition, it should look like this:

 if (condition) {
        // code
 }

You also don't close your isEven function. You need to put a closing } before you call the function.


#7

This code should work.

var isEven = function(number) {

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

 else if (isNaN (number)===true) {
     return "The input is not a number.";
 }

 else {
     return false;
 }

};

isEven(03);


#8

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