+ 2

I want a input to return a random response from one of 3 set lines of text, how do i go about that ?

using JavaScript to process input and reply with at random one of these replys: . hi "input" how are you? . how was your day "input" ? . "input" whats you favorite color?

30th Jun 2017, 12:53 AM
Hoeft Brian
Hoeft Brian - avatar
2 ответов
+ 2
var greets = [ "Hi {input} how are you?", "How was your day {input} ?", "{input}, whats you favorite color?" ] var input = "Serena" var index = ~~(Math.random() * 3); var output = greets[index].replace(/{input}/,input); console.log(output);
30th Jun 2017, 3:58 AM
Calviղ
Calviղ - avatar
+ 1
Put the text where each line is an element of an array. Then pick a random number using `Math.random();`. Set the random number to a variable and output `array[thatnumberyoualreadygotfromrandom];`
30th Jun 2017, 3:15 AM
Ian Golsby