0

Struggling with Switch Statement Exercises

Instructions: Switch statements The user can choose the color theme for the browser: 1. Light 2. Dark 3. Nocturne 4. Terminal 5. Indigo You are given a program that takes the number as input. Complete the program so that it will output to the console the theme according to input number. Sample Input 2 Sample Output Dark This is my latest try: function main() { var themeNumber = parseInt(readLine(), 10) /* 1 - Light 2 - Dark 3 - Nocturne 4 - Terminal 5 - Indigo */ // Your code here switch (main){ case 1: var text = "Light"; console.log(light); break; } } I haven't done all the statements as I keep getting no output for the first test. Can someone help me work out what I am doing wrong?

4th Dec 2020, 5:39 PM
Zach Best
Zach Best - avatar
6 Réponses
0
In the line, `console.log(light)` there is no variable named `light`. Hint: you stored "Light" in the variable named `text`
4th Dec 2020, 5:49 PM
XXX
XXX - avatar
0
i have made the following changes but the test still reports no output when it runs: i am confused on why i am getting no output when i am declaring the variable. function main() { var themeNumber = parseInt(readLine(), 10) /* 1 - Light 2 - Dark 3 - Nocturne 4 - Terminal 5 - Indigo */ // Your code here switch (main){ case 1: var text = "Light"; console.log(text); break; } }
4th Dec 2020, 7:13 PM
Zach Best
Zach Best - avatar
0
Sorry, I didn't see it the first time. `main` is function. Why have you put `main` in the switch statement? `switch (main) {` You have to check the `themeNumber` variable, put that in the switch statement
4th Dec 2020, 8:05 PM
XXX
XXX - avatar
0
oh thanks. wow such i dumb mistake lord i should of spotted that ages ago
4th Dec 2020, 8:14 PM
Zach Best
Zach Best - avatar
0
function main() { var themeNumber = parseInt(readLine(), 10) /* 1 - Light 2 - Dark 3 - Nocturne 4 - Terminal 5 - Indigo */ // Your code here switch(themeNumber){ case 1: console.log("Light"); break; case 2: console.log("Dark"); break; case 3: console.log("Nocturne"); break; case 4: console.log("Terminal"); break; default: console.log("Indigo"); } }
26th Sep 2022, 10:18 AM
Mohd Faizy
Mohd Faizy - avatar
0
function main() { var themeNumber = parseInt(readLine(), 10); // Inicializamos una variable para almacenar el tema. var theme; // Utilizamos una declaración switch para asignar el número de entrada al tema correspondiente. switch (themeNumber) { case 1: theme = "Light"; break; case 2: theme = "Dark"; break; case 3: theme = "Nocturne"; break; case 4: theme = "Terminal"; break; case 5: theme = "Indigo"; break; default: theme = "Desconocido"; // Manejamos los casos en los que la entrada no sea 1-5. } // Mostramos el tema en la consola. console.log(theme); }
26th Oct 2023, 12:48 PM
KEVIN ALEJANDRO VALENCIA VALENCIA
KEVIN ALEJANDRO VALENCIA VALENCIA - avatar