it is showing error Invalid left-hand side in assignment? what is wrong in this code can any once help ?
2 Answers
The problem is that you have expressions returning true
, which you then attempt to assign values.
What you meant to do is:
var a = document.getElementById('number').value;
switch (+a){
case 1 : alert('enter one'); break;
case 2 : alert('enter two'); break;
case 3 : alert('enter three'); break;
case 4 : alert('enter four'); break;
}
The switch statement handles the comparisons for you. case 1
is the case where a is equal to 1.
Also, you want to get the element with the id "number", and instead of switch(a)
, you want switch(+a)
.
Problem is with your JavaScript. Syntax for Switch case is wrong. This is how it should be:
switch(a) {
case 1: alert("enter one");break;
case 2: alert("enter two");break;
case 3: alert("enter three");break;
case 4: alert("enter four");break;
}
JavaScript documentation
-
@popoornimapuligadda replace your switch case code with above code. Mar 24, 2017 at 13:03