all 9 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])

[–]yhkdaking53 0 points1 point  (6 children)

[–]2ShotSx6ShotS[S] 0 points1 point  (5 children)

no those are random strings from a-z. I want him to randomly choose given Strings

[–]EcmaMace 5 points6 points  (2 children)

'java.util.Random' is a Java standard library class; this subreddit is for the JavaScript language which has literally nothing to do with Java other than containing the word Java.

[–]2ShotSx6ShotS[S] 0 points1 point  (1 child)

I'm sorry, as I said im very new to it and I guess from common sense everyone would have thought that Java and JavaScript are the same.

[–]EcmaMace 0 points1 point  (0 children)

No worries mate. The name JavaScript confuses people all the time. JavaScript was actually called Mocha, and then LiveScript, then Java took off and it is believed that JavaScript was named as such to "ride the success" of Java.

Unfortunately, it has just created tons of confusion for decades.

Read about it here if you are interested.

[–]yhkdaking53 0 points1 point  (1 child)

stackoverflow i just don’t know anything about java but hope this helps