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

  • 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. Commented Mar 24, 2017 at 13:03
  • remove a==1 and similar. it is not needed
    – Ashwani
    Commented Mar 24, 2017 at 14:07

2 Answers 2


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