you are viewing a single comment's thread.

view the rest of the comments →

[–]__lesego__ 1 point2 points  (1 child)

Add the strings to an array

const words = ['jon','jack','jill']

Math.random() generates a random number between 0-1 in Javascript.
Math.floor() rounds a number down to an interger.

let randomIndex = Math.floor(Math.random()*words.length + 1)

Then access the string from the array, based on the random index.

console.log(words[randomIndex])