0
Why is line 6 not working? đŁ
window.onload = () => { let h1, h2, h3, h4, h5, h6, hc, vhcs; let genbtn = document.getElementById("genhcode"); genbtn.onclick = () => { vhcs = "abcdef123456"; h1, h2, h3, h4, h5, h6 = vhcs[Math.floor(Math.random() * 12)] console.log(h1) } } I want it to select a random character from the variable vhcs, but it just outputs (null) Why?
2 Answers
+ 2
We cant set value using syntax:
h1,h2,h3 = "some value";
If you try you will get undefined
We can only define variables in this way
You need to set value per each variable like this:
h1 = "some value";
h2 = "other value";
Or you can use this method:
[h1,h2,h3] = ["first variable value", "2nd var value","3rd value"]