if statement is true, the block of code following it is executed. What about when that condition is false? Normally nothing would happen. With an else statement, an alternate block of code can be executed.
if (num > 10) {
return "Bigger than 10";
} else {
return "10 or Less";
}
if statements into a single if/else statement.
if statement in the editor
testString: assert(code.match(/if/g).length === 1, 'You should only have one if statement in the editor');
- text: You should use an else statement
testString: assert(/else/g.test(code), 'You should use an else statement');
- text: testElse(4) should return "5 or Smaller"
testString: assert(testElse(4) === "5 or Smaller", 'testElse(4) should return "5 or Smaller"');
- text: testElse(5) should return "5 or Smaller"
testString: assert(testElse(5) === "5 or Smaller", 'testElse(5) should return "5 or Smaller"');
- text: testElse(6) should return "Bigger than 5"
testString: assert(testElse(6) === "Bigger than 5", 'testElse(6) should return "Bigger than 5"');
- text: testElse(10) should return "Bigger than 5"
testString: assert(testElse(10) === "Bigger than 5", 'testElse(10) should return "Bigger than 5"');
- text: Do not change the code above or below the lines.
testString: assert(/var result = "";/.test(code) && /return result;/.test(code), 'Do not change the code above or below the lines.');
```