0
JavaScript selecting random numbers(for color generation)
var letters = '0123456789ABCDEF'; letters[Math.floor(Math.random() * 16)] Here why have we used [ ] and also can we take any number instead of 16 ?
1 Odpowiedź
+ 2
the [] are to get a certain character from the String 'letters' the 16 is just the length of the String letters, you could use smaller values too, but using negative values or values greater than 16 can result in errors, since the index wouldn't be present in the String anymore ...
hope this helped
happy coding ! 😄