Introducing Else If Statements bug?

Introducing Else If Statements bug?
0.0 0

#1

Tell us what’s happening:
So freecodecamp won’t accept my answer because it says I don’t have two else statements? There’s a green check mark next to my “two if statements” statement so it must recognize else if as an if statement. Is this just a bug?

Your code so far

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);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:


#2

You have a missing closing brace, right below the last closing brace.


#3

I’m sorry, where? I added one right below the last closing brace but it still doesn’t work, wouldn’t that be kind of redundant?


#4

Can you show us the new code after adding the closing brace?

To enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#5

When I add a last closing brace, it passes for me. Count your opening braces and closing braces. See which ones are closing which.


#6

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);


#7

If you look at the test results, you will see you are expected to use one more else statement. Your original code was only missing a closing brace.


#8

Ohhh I wasn’t adding the closing brace to the code I posted, I reset the code after I asked this question so I was adding it to this other method I was trying. It worked, thanks everyone!