if
for verdadeira, o bloco de código que a segue é executado. E quando essa condição é falsa? Normalmente nada aconteceria. Com uma instrução else
, um bloco de código alternativo pode ser executado. if (num> 10) {
return "Maior que 10";
} outro {
return "10 ou menos";
}
if
em uma única instrução if/else
. if
no editor
testString: 'assert(code.match(/if/g).length === 1, "You should only have one if
statement in the editor");'
- text: Você deveria usar uma instrução else
testString: 'assert(/else/g.test(code), "You should use an else
statement");'
- text: testElse(4)
deve retornar "5 ou menor"
testString: 'assert(testElse(4) === "5 or Smaller", "testElse(4)
should return "5 or Smaller"");'
- text: testElse(5)
deve retornar "5 ou menor"
testString: 'assert(testElse(5) === "5 or Smaller", "testElse(5)
should return "5 or Smaller"");'
- text: testElse(6)
deve retornar "maior que 5"
testString: 'assert(testElse(6) === "Bigger than 5", "testElse(6)
should return "Bigger than 5"");'
- text: testElse(10)
deve retornar "maior que 5"
testString: 'assert(testElse(10) === "Bigger than 5", "testElse(10)
should return "Bigger than 5"");'
- text: Não mude o código acima ou abaixo das linhas.
testString: 'assert(/var result = "";/.test(code) && /return result;/.test(code), "Do not change the code above or below the lines.");'
```