Sometimes the randomly-generated letter equals to ‘undefined’
Anyone know why?
Code:
<script type="text/javascript">
var myArray= ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
randomnumber=Math.floor(Math.random()*27);
alert(myArray[randomnumber]);
Well, it could have something to do with your Math.floor(Math.random()*27) using the number 27 when there are 26 letters in the English alphabet.
so you get a blank in each box 1/27 of all loads. However, once “#next” has been seeded it will always stay a “letter” because you’re replacing it with
When
randomnumber=27good[randomnumber]=undefinedand$("#next").text(undefined)does nothing so the contents of “#next” remain unchanged. Still broken, less obvious. Just change 27 to 26 and you’re done.