0

I have been battling with this code since couple of days and its giving me issue. the other functions are working perfectly except this EQUAL function.

Below is the code

equal.addEventListener("click", function(e){
        if (screen.value = "") {
           screen.value = "";
         } else{
             console.log(screen.value);
             let answer = eval(screen.value);
             screen.value = answer;
         } 
     });
  • Do you know how to use your browser to debug JavaScript? A little scrutiny of each line's value as it runs would've made the mistake fairly apparent. Try setting a breakpoint on line 2 and selecting `screen.value = ""`. – isherwood Aug 01 '22 at 21:23
  • see: [What is the difference between the `=` and `==` operators and what is `===`? (Single, double, and triple equals)](https://stackoverflow.com/questions/11871616/what-is-the-difference-between-the-and-operators-and-what-is-si) – pilchard Aug 01 '22 at 22:28

1 Answers1

1

The first thing jumping out to me is that you're using the assignment operator rather than comparison in the if statement. Maybe this resolves your issue:

if (screen.value == "") {
           screen.value = "";
         } else{