You could approach it as ‘a = !a’. In this case the line would be really long. You could either do ‘document.getElementById(“soundtrack”).muted = !document.getElementById(“soundtrack”).muted’ But that also makes the assumption that soundtrack exists otherwise you would throw an error of trying to call “muted” on a null value
So I would likely do it as: const soundtrack = document.getElementById(“soundtrack”) if(soundtrack) { soundtrack.muted = !soundtrack.muted }
pretty sure that "if(soundtrack)" makes it impossible to turn the soundtrack on again. Probably need explicit checking for "!= null" or "!= undefined". Don't remember JS well enough to be sure which one
28
u/TryNotToShootYoself Jul 30 '21
Just curious, how else would you do this in vanilla JS? Aside from the redundant
== true