How to pass "Basic JavaScript: Logical Order in If Else Statements"

Tell us what’s happening:

Basically my code works fine it satisfies all necessary requirements for the challenge but it isn’t passing the tests, it’s only missing one test “You should not change the code above or below the specified comments.” But the thing is Even if i reset my code and change nothing it still fails that test to add on to that this test isn’t updated either so the video tutorial is out of date can anyone help me out?

Your code so far
function testElse(val) {
if(val <= 5) {
return “5 or Smaller”;
} else {
return “Bigger than 5”;
}
}

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


function testElse(val) {
if(val <= 5) {
  return "5 or Smaller";
}  else {
  return "Bigger than 5";
}
}
// Change this value to test
testElse(7);


Your browser information:

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

Challenge: Logical Order in If Else Statements

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

Did you change the name of the function?

Yeah it required me too because the other tests say things like testElse(4) should return “5 or Smaller”
so I had to change the original function name to get the other tests to pass

You shouldn’t ever change the function name of a function provided in the curriculum. I’m not sure what you are looking at to make you think otherwise.
image

Normally I would agree it’s been the same for the rest of the curriculum but for this my instructions show
Order is important in if , else if statements.

The function is executed from top to bottom so you will want to be careful of what statement comes first.

Take these two functions as an example.

Here’s the first:

function foo(x) {
  if (x < 1) {
    return "Less than one";
  } else if (x < 2) {
    return "Less than two";
  } else {
    return "Greater than or equal to two";
  }
}

And the second just switches the order of the statements:

function bar(x) {
  if (x < 2) {
    return "Less than two";
  } else if (x < 1) {
    return "Less than one";
  } else {
    return "Greater than or equal to two";
  }
}

While these two functions look nearly identical if we pass a number to both we get different outputs.

foo(0) // "Less than one"
bar(0) // "Less than two"

Change the order of logic in the function so that it will return the correct statements in all cases.

Passed

You should only have one if statement in the editor

Passed

You should use an else statement

testElse(4) should return “5 or Smaller”

testElse(5) should return “5 or Smaller”

testElse(6) should return “Bigger than 5”

testElse(10) should return “Bigger than 5”.

You should not change the code above or below the specified comments.

Even though in the video it uses the function name you mentioned before

The challenge on which you clicked the Ask for Help button is not the same challenge for the code you posted. I assume the challenge you are working on is Introducing Else If Statements?

If so, you still should not be changing the name of the function. It should be testElseIf and not testElse. Why do you think you should change the function name?

Try doing a browser cache and hard reload. You really don’t want to change the function name.

That worked I reloaded my page and it changed the instructions thanks!