{
    "componentChunkName": "component---src-templates-challenges-classic-show-tsx",
    "path": "/learn/javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements",
    "result": {"data":{"challengeNode":{"challenge":{"block":"basic-javascript","title":"Selezionare tra molte opzioni con le istruzioni Switch","description":"<section id=\"description\">\n<p>Se hai molte opzioni tra cui scegliere, usa un'istruzione <dfn>switch</dfn>. Un'istruzione <code>switch</code> verifica un valore e può avere molte istruzioni <dfn>case</dfn> che definiscono vari valori possibili. Le istruzioni vengono eseguite dal primo valore <code>case</code> che combacia e fino a quando non si incontra un <code>break</code>.</p>\n<p>Ecco un esempio di un'istruzione <code>switch</code>:</p>\n<pre><code class=\"language-js\">switch(lowercaseLetter) {\n  case \"a\":\n    console.log(\"A\");\n    break;\n  case \"b\":\n    console.log(\"B\");\n    break;\n}\n</code></pre>\n<p>I valori <code>case</code> vengono testati con uguaglianza stretta (<code>===</code>). Il <code>break</code> dice a JavaScript di interrompere l'esecuzione delle istruzioni. Se il <code>break</code> viene omesso, sarà eseguita la successiva istruzione.</p>\n</section>","hasEditableBoundaries":false,"instructions":"<section id=\"instructions\">\n<p>Scrivi una dichiarazione switch che testa <code>val</code> e imposta il valore di <code>answer</code> per le seguenti condizioni:<br>\n<code>1</code> - <code>alpha</code><br>\n<code>2</code> - <code>beta</code><br>\n<code>3</code> - <code>gamma</code><br>\n<code>4</code> - <code>delta</code></p>\n</section>","notes":null,"removeComments":null,"challengeType":1,"helpCategory":"JavaScript","videoUrl":"https://scrimba.com/c/c4mv4fm","superBlock":"javascript-algorithms-and-data-structures","certification":"javascript-algorithms-and-data-structures","translationPending":false,"forumTopicId":18277,"fields":{"blockName":"Basic JavaScript","slug":"/learn/javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements","tests":[{"text":"<p><code>caseInSwitch(1)</code> dovrebbe avere il valore stringa <code>alpha</code></p>","testString":"assert(caseInSwitch(1) === 'alpha');"},{"text":"<p><code>caseInSwitch(2)</code> dovrebbe avere il valore stringa <code>beta</code></p>","testString":"assert(caseInSwitch(2) === 'beta');"},{"text":"<p><code>caseInSwitch(3)</code> dovrebbe avere il valore stringa <code>gamma</code></p>","testString":"assert(caseInSwitch(3) === 'gamma');"},{"text":"<p><code>caseInSwitch(4)</code> dovrebbe avere il valore stringa <code>delta</code></p>","testString":"assert(caseInSwitch(4) === 'delta');"},{"text":"<p>Non dovresti usare alcuna dichiarazione <code>if</code> o <code>else</code></p>","testString":"assert(!/else/g.test(code) || !/if/g.test(code));"},{"text":"<p>Dovresti avere almeno 3 istruzioni <code>break</code></p>","testString":"assert(code.match(/break/g).length > 2);"}]},"required":[],"usesMultifileEditor":false,"challengeFiles":[{"fileKey":"scriptjs","ext":"js","name":"script","contents":"function caseInSwitch(val) {\n  let answer = \"\";\n  // Ne changez que le code en dessous de cette ligne\n\n\n\n  // Ne changez le code qu'au-dessus de cette ligne\n  return answer;\n}\n\ncaseInSwitch(1);","head":"","tail":"","editableRegionBoundaries":[],"history":["script.js"]}]}}},"pageContext":{"challengeMeta":{"certification":"javascript-algorithms-and-data-structures","superBlock":"javascript-algorithms-and-data-structures","block":"basic-javascript","template":"","required":[],"nextChallengePath":"/learn/javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements","prevChallengePath":"/learn/javascript-algorithms-and-data-structures/basic-javascript/golf-code","id":"56533eb9ac21ba0edf2244dd"},"projectPreview":{"showProjectPreview":false,"challengeData":{"challengeType":1,"challengeFiles":[{"name":"script","ext":"js","contents":"function rangeOfNumbers(startNum, endNum) {\n  if (endNum - startNum === 0) {\n    return [startNum];\n  } else {\n    const numbers = rangeOfNumbers(startNum, endNum - 1);\n    numbers.push(endNum);\n    return numbers;\n  }\n}","head":"","tail":"","history":["script.js"]}],"required":[],"template":""}},"slug":"/learn/javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements"}},
    "staticQueryHashes": ["1670270925","3851966407"]}