Chaining If Statements

function testSize(num) {
  // Only change code below this line
  
  if (num >= 20){
    return "Huge";
  }
  else if (num < 20){
    return "Large";
  }
  else if (num < 15){
    return "Medium";
  }
  else if (num < 10){
    return "Small";
  }
  else if (num < 5){
    return "Tiny";
  }
  // Only change code above this line
}

I have thought about the logical order of things, but somehow when running the test, it says that

testSize(0) should return "Tiny"

I know I reversed the order on purpose, but shouldn’t “0” still return “Tiny” because it fails the first few conditions?

(0 < 20) is true, it’s also less than 15, 10 and 5

1 Like

Ah duh. I am sorry for asking such a stupid question!

There are no stupid questions. We get a thought stuck in our heads sometimes and can’t figure out why our logic is working until someone else points it out.

1 Like