Introducing Else Statements- A bug?

Tell us what’s happening:

I created the code below and also used the example code in the hint as a secondary test, but the grader keeps claiming that the function does not return the correct result if 4 and 5 are used as arguments What can I do now?

Marie

Your code so far


function testElse(val) {
  var result = "";
  // Only change code below this line
  
  if (val > 5) {
    result = "Bigger than 5";
  }
  
  else {
    result = "5 or smaller";
  }
  
  // Only change code above this line
  return result;
}

// Change this value to test
testElse(4);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0.

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

Hi!

While I prefer to check for the smaller value like so:

  if (val <= 5) {
    result = "5 or Smaller";
  } else {
    result = "Bigger than 5";
  }

due to readability, your code is correct. The only thing why your solution fails is the error in the string.

result = "5 or smaller";

should be:

result = "5 or Smaller";
2 Likes

Thank you!

I have corrected the mistake and also reset the code according to your suggestion. It really is more intuitive that way

Marie