Introducing Else If Statements: Can't pass it

I can’t pass what am I doing wrong? And can someone explain it step by step really simple.

function testElseIf(val) {
  if (val > 10) {
    return "Greater than 10";
  }
  
  else if (val < 5) {
    return "Smaller than 5";
  }
  
  return "Between 5 and 10";
}

// Change this value to test
testElseIf(7);

Your code so far


function testElseIf(val) {
  if (val > 10) {
    return "Greater than 10";
  }
  
  else if (val < 5) {
    return "Smaller than 5";
  }
  
  return "Between 5 and 10";
}

// Change this value to test
testElseIf(7);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.1 Safari/605.1.15.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/introducing-else-if-statements

What do the failing tests say?

You should have at least two else statements

You should have closing and opening curly braces for each condition in your if else statement

It tells me what is wrong but, i don’t understand why?
The task is:
Convert the logic to use else if statements. Doesn’t tell us anything about the curly brakets. Our a second else if statment

Well, you only have one else block.

1 Like

Adding one like in the code bellow still gets me the same error

function testElseIf(val) {
  else if (val > 10) {
    return "Greater than 10";
  }
  
  else  (val < 5) {
    return "Smaller than 5";
  }
  
  return "Between 5 and 10";
}

// Change this value to test
testElseIf(7);

That’s not valid code. You have an else before you have an if. Look at the example code on in the challenge description.

1 Like

The test require two if’s and two else statements. So really you need one if, and else if, and an else.

1 Like

Passed it

function testElseIf(val) {
  if (val > 10) {
    return "Greater than 10";
  } else if (val < 5) {
    return "Smaller than 5";
  }
  else {  
    return "Between 5 and 10";
} }

// Change this value to test
testElseIf(7);

¿Can anyone point out what i am not seeing here?