Why doesn’t my Eps work?

Asked

Viewed 76 times

-4

const alun = document.querySelector("#bottomaluno")

alun.addEventListener('click', addaluno)

function addaluno() { 

    if(display = 'none') { 
        document.querySelector("#alunos").style.display = 'block';
    } else{
        document.querySelector("#alunos").style.display = 'none';
    }
 }

3 answers

3

Because one equals signal is value assignment and not comparison, to be dfe comparison has to use 2 equals signals, so:

if(display == 'none') { 
  • even so does not work the only format that worked was with =, with two "==" of this error Uncaught Referenceerror: display is not defined at Htmlbuttonelement.addaluno (addfield.js:6)

  • @Peter that there is another error and is not equal to the code shown in the question.

  • is exactly the same code, when I use = it only works if, when I use either == or === of this undefined display error and it doesn’t work if or Else

  • Caro @Pedro a varivel display does not exist, is not part of the code quoted above, or else the code is simply all wrong.

  • then he’s all wrong :(

1

When using:

display = 'none'

you are setting the value 'None' to display, which will not work The correct would be to compare using:

display == 'none'

Still you would be comparing only the value, and not the type, so I would recommend using:

display === 'none'
  • even so does not work the only format that worked was with =, with two "==" or with three "===" of that error " Uncaught Referenceerror: display is not defined at Htmlbuttonelement.addaluno", ps did not change at all the code.

-2

" = " attribution, " == " equality, " === " Strictly equal.

display == 'none'

  • even so does not work the only format that worked was with =, with two "==" or with three "===" of that error " Uncaught Referenceerror: display is not defined at Htmlbuttonelement.addaluno", ps did not change at all the code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.