switch
может быть проще писать, чем многие прикованные if
/ else if
. Следующие: если (val === 1) {можно заменить на:
answer = "a";
} else if (val === 2) {
answer = "b";
} else {
answer = "c";
}
switch (val) {
Дело 1:
answer = "a";
ломать;
случай 2:
answer = "b";
ломать;
по умолчанию:
answer = "c";
}
if
/ else if
оператор switch
. else
утверждений в любом месте редактора
testString: 'assert(!/else/g.test(code), "You should not use any else
statements anywhere in the editor");'
- text: Вы не должны использовать какие-либо инструкции if
в редакторе
testString: 'assert(!/if/g.test(code), "You should not use any if
statements anywhere in the editor");'
- text: Вы должны иметь по крайней мере четыре break
заявления
testString: 'assert(code.match(/break/g).length >= 4, "You should have at least four break
statements");'
- text: chainToSwitch("bob")
должен быть "Marley"
testString: 'assert(chainToSwitch("bob") === "Marley", "chainToSwitch("bob")
should be "Marley"");'
- text: chainToSwitch(42)
должен быть «Ответ»
testString: 'assert(chainToSwitch(42) === "The Answer", "chainToSwitch(42)
should be "The Answer"");'
- text: chainToSwitch(1)
должен быть «Нет №1»
testString: 'assert(chainToSwitch(1) === "There is no #1", "chainToSwitch(1)
should be "There is no #1"");'
- text: chainToSwitch(99)
должен быть «пропустил меня этим!»
testString: 'assert(chainToSwitch(99) === "Missed me by this much!", "chainToSwitch(99)
should be "Missed me by this much!"");'
- text: chainToSwitch(7)
должен быть «Ate Nine»
testString: 'assert(chainToSwitch(7) === "Ate Nine", "chainToSwitch(7)
should be "Ate Nine"");'
- text: chainToSwitch("John")
должен быть «» (пустая строка)
testString: 'assert(chainToSwitch("John") === "", "chainToSwitch("John")
should be "" (empty string)");'
- text: chainToSwitch(156)
должен быть «" (пустая строка)
testString: 'assert(chainToSwitch(156) === "", "chainToSwitch(156)
should be "" (empty string)");'
```