--- id: 56533eb9ac21ba0edf2244de title: Adding a Default Option in Switch Statements challengeType: 1 guideUrl: 'https://portuguese.freecodecamp.org/guide/certificates/adding-a-default-option-in-switch-statements' videoUrl: '' localeTitle: Adicionando uma opção padrão em instruções de troca --- ## Description
Em uma instrução switch , você pode não conseguir especificar todos os valores possíveis como instruções case . Em vez disso, você pode adicionar a instrução default que será executada se nenhuma instrução case correspondente for encontrada. Pense nisso como a final else declaração em um if/else cadeia. Uma declaração default deve ser o último caso.
switch (num) {
valor do caso1:
statement1;
pausa;
valor do caso2:
statement2;
pausa;
...
padrão:
defaultStatement;
pausa;
}
## Instructions
Escreva uma instrução switch para definir a answer para as seguintes condições:
"a" - "maçã"
"b" - "pássaro"
"c" - "gato"
default - "stuff"
## Tests
```yml tests: - text: switchOfStuff("a") deve ter um valor de "apple" testString: 'assert(switchOfStuff("a") === "apple", "switchOfStuff("a") should have a value of "apple"");' - text: switchOfStuff("b") deve ter um valor de "bird" testString: 'assert(switchOfStuff("b") === "bird", "switchOfStuff("b") should have a value of "bird"");' - text: switchOfStuff("c") deve ter um valor de "cat" testString: 'assert(switchOfStuff("c") === "cat", "switchOfStuff("c") should have a value of "cat"");' - text: switchOfStuff("d") deve ter um valor de "stuff" testString: 'assert(switchOfStuff("d") === "stuff", "switchOfStuff("d") should have a value of "stuff"");' - text: switchOfStuff(4) deve ter um valor de "stuff" testString: 'assert(switchOfStuff(4) === "stuff", "switchOfStuff(4) should have a value of "stuff"");' - text: Você não deve usar nenhuma instrução if ou else testString: 'assert(!/else/g.test(code) || !/if/g.test(code), "You should not use any if or else statements");' - text: Você deve usar uma declaração default testString: 'assert(switchOfStuff("string-to-trigger-default-case") === "stuff", "You should use a default statement");' - text: Você deve ter pelo menos 3 declarações de break testString: 'assert(code.match(/break/g).length > 2, "You should have at least 3 break statements");' ```
## Challenge Seed
```js function switchOfStuff(val) { var answer = ""; // Only change code below this line // Only change code above this line return answer; } // Change this value to test switchOfStuff(1); ```
## Solution
```js // solution required ```