This forum is now read-only. Please use our new forums at

190 points
Submitted by
about 6 years ago

How do I turn my numbers into letters?

I can make it so that the output will give me one random position in the array via a pre-determined number, but I don't know how to output a letter from the array instead. Pretty much, I have the random positioning right, but I need that letter from the position and not the number.

var array = ["P", "e", "a", "n", "u", "t", "s", "R", "o", "c", "k"];
var out =

The bolded part is the part I have been changing and so far have gotten to.

0 votes


The Math.floor() function outputs a number, and in this case you have it so it outputs a random number representing the location of a number in the array.

The easiest way to fix this would be to simply make the third like:
console.log(array[out]); — this outputs the letter in the position your random function found.

Hope that makes sense.

956 points
Submitted by
Lukas W
about 6 years ago

0 votes


In addition to what Lukas stated:

Math.random() should be multiplied by the length of the array to generate numbers from 0 to array.length-1, inclusive.

2280 points
Submitted by
Stuart Connall
over 5 years ago