0

What’s wrong with this JavaScript code?

It’s one of the coding exercise in SoloLearn, after//your code here is my coding , which I don’t know what went wrong in the JavaScript using “switch”. function main() { var themeNumber = parseInt(readLine(), 10) /* 1 - Light 2 - Dark 3 - Nocturne 4 - Terminal 5 - Indigo */ // Your code here 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; default: document.write("Indigo");} } The question is : 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

26th Oct 2020, 10:17 PM
C Yam
C Yam - avatar
12 Answers
+ 3
Use console.log(output); Cheri Yan document.write() is used to output on Web documents. console.log() outputs on js standard output console...
26th Oct 2020, 10:52 PM
Jayakrishna 🇼🇳
+ 6
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"); }
20th Aug 2021, 4:05 PM
Abdoul Aziz diallo
Abdoul Aziz diallo - avatar
+ 5
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"); } } Good Luck
25th Jan 2022, 8:04 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
+ 2
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");} }
25th Aug 2021, 9:29 AM
MD RAKIBUL HASSAN NAYON
MD RAKIBUL HASSAN NAYON - avatar
+ 1
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. this 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"); default: console.log("Color no found"); } } But i have some problem with 5 secret test
24th Dec 2021, 9:44 PM
Maksym
Maksym - avatar
+ 1
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; default: console.log("Another color"); } }
13th Jan 2023, 4:12 PM
OBADA AL RATROUT
0
If readLine method works fine, then try by changing default case to case 5:. Logically it may work but if input is other than 5 then it don't any output I think. Edit : hoping code have function calling statement : main()
26th Oct 2020, 10:46 PM
Jayakrishna 🇼🇳
0
i tried using case 5, it doesnt work. in the practice output, it says “document is not defined in the main” i am just confused and wonder how to solve this problem. its a practicing problem using “javascript switch”
26th Oct 2020, 10:51 PM
C Yam
C Yam - avatar
0
thanks a lot . ok. so instead of using “document.write” need to use “console.log” instead. thanks it works now
26th Oct 2020, 11:03 PM
C Yam
C Yam - avatar
0
Yes. You're welcome..
26th Oct 2020, 11:04 PM
Jayakrishna 🇼🇳
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; case 5: console.log("Indigo"); default: console.log("Color no found"); } }
14th Feb 2022, 12:44 PM
Ali Haneef
Ali Haneef - avatar
0
console.log(`Welcome, Tommy`);
18th Sep 2023, 10:26 PM
Akhideno Joseph
Akhideno Joseph - avatar