javascript why it performs the second function before the first one ? | SoloLearn: Learn to code for FREE!

+2

javascript why it performs the second function before the first one ?

var weapon = "knife"; function changetoak(){ weapon = "ak47" ; akbtn.innerHTML = "unequip"; akbtn.onclick = unequipak(); } function unequipak(){ weapon = "knife"; akbtn.innerHTML = "equip"; }

js

3/17/2020 1:48:06 PM

Omar Dodo Gawad

1 Answer

New Answer

+5

If you do this akbtn.onclick = unequipak(); You are calling the `unequipak` function instead of assigning the function as event handler. Try like this: akbtn.onclick = unequipak;