New course! Every coder should learn Generative AI!
Try a free lesson0
The switch Statement - JS practice - 17.2 Dark Theme task problem
whyyy my code does'nt work... :((( Problem: 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 MY CODE: function main() { var themeNumber = parseInt(readLine(), 10) switch (themeNumber) { case 1: document.write("Light"); break; case 2: document.write("Dark"); break; case 3: document.write("Nocturne"); break; case 4: document.write("Terminal"); break; case 5: document.write("Indigo"); break; }
11 Answers
+ 8
It's conSole.log() not conCole.log()
+ 5
In Sololearn JavaScript code practices, you need to use console.log() to print the output.
Also, you're missing `}` at the end.
+ 2
OMG....
burning with shame...
many thx again...
Final output:
function main() {
var themeNumber = parseInt(readLine(), 10)
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;
case 5:
console.log("Indigo");
break;
}
}
+ 1
thx, I've changed to "console.log" and added '}' at the end...
but this code still produce error...
function main() {
var themeNumber = parseInt(readLine(), 10)
switch(themeNumber) {
case 1:
concole.log("Light");
break;
case 2;
concole.log("Dark");
break;
case 3:
concole.log("Nocturne");
break;
case 4:
concole.log("Terminal");
break;
case 5:
concole.log("Indigo");
break;
}
}
OUTPUT ERROR:
/usercode/file0.js:23
case 2;
^
SyntaxError: Unexpected token ';'
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
0
desde hace dos días estoy en esta practica con este código ---->
function main() {
var themeNumber = parseInt(readLine(), 10)
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;
case 5:
console.log("Indigo");
break;
}
}
console.log(main());
¿entienden?
..... console.log(main())
solo por está linea, el Output era "undefined";
Dos días; buscando errores en mi código. Intenté con un editor de js, y si funciono PERO en sololearn NO ...
pues en la practica no se coloca ... console.log(main()).
0
here is any problem with my code?
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;
case 5:
console.log("Indigo");
break;
}
}
0
I had the same problem as you it helped me to delete the comments and then it worked
0
Can someone explain to me what’s wrong with this code
function main() {
var themeNumber = parseInt(readLine(), 10)
switch (themeNumber){
case1:
console.log ("Light");
break;
case 2:
console.log ("Dark");
break;
case 3:
console.log ("Nocturne");
break;
case 4:
console.log ("Terminal");
break;
case 5:
console.log ("Indigo");
break;
}
}
0
Readline…33
0
Finish
0
function main() {
var themeNumber = parseInt(readLine(), 33)