1

it is showing error Invalid left-hand side in assignment? what is wrong in this code can any once help ?

2
  • 1
    Don't submit code in a image- it makes it harder for other users to run that code, or use it in an answer. See the formatting guide. Mar 24, 2017 at 13:03
  • remove a==1 and similar. it is not needed
    – Ashwani
    Mar 24, 2017 at 14:07

2 Answers 2

1

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).

0

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

1
  • @popoornimapuligadda replace your switch case code with above code. Mar 24, 2017 at 13:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .