i was trying to print the value of variable 'x' after switch block.However, i didnt put any expression to switch so it could escape the default case and print the value of x. But in line no 13,the x wont show any value in case there is a switch block in the code and it only worked when i removed the switch block.
let x = "0";
switch () { //switch with no expression
case 0:
text = "Off";
break;
case 1:
text = "On";
break;
default:
text = "No value found";
}
document.getElementById("demo").innerHTML = x; //line no. 13
There is a syntax error.
Your switch needs to have some expression.
I mean switch(something here)
Because of the syntax error the script fails to execute further and hence you are not getting the output
The Switch does not accept empty expressions you should switch a variable or it will generate an error .. but if you want to you can use this one
let x = "0";
switch (true) { //switch with no expression
case 0:
text = "Off";
break;
case 1:
text = "On";
break;
default:
text = "No value found";
}
document.getElementById("demo").innerHTML = x; //line no. 13