Add a button and allow a random value to appear in the text box | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Add a button and allow a random value to appear in the text box

I feel like I should not bother the people in Stack Overflow too much. So, I am creating a Mad-Libs type thing where the user can input the values. But, what if the user does not know what to put? I'd like to add a button and when the user clicks on it, it will show one value of an array. Thanks for your help!

26th Dec 2019, 2:56 AM
Shannon
Shannon - avatar
2 Answers
0
I'm a noob in JavaScript but I guess this could work: var Responses = [ "Yes", "No", ]; getRandom = (array) => {return array[Math.floor(Math.random() * array.length)];} console.log(getRandom(Responses));
26th Dec 2019, 3:18 AM
SoundInfinity
SoundInfinity - avatar
0
What have you done so far?
26th Dec 2019, 7:20 AM
Logomonic Learning
Logomonic Learning - avatar