var submit = document.getElementById("submit");
var value = document.getElementById("value");
var greeting = ['hi', 'hello', 'Hlw', 'hello jii', 'hey', 'helo', 'hi there', 'hey']
var greetReply = ['hlw', 'kisu na', 'gaan shuni'];
submit.addEventListener('click', () => {
const reply = Math.floor(Math.random() * greetReply.length); // random reply!
for (let i = 0; i < greeting.length; i ) {
if(value.value === greeting[i]){
console.log(reply)
}
}
})
CodePudding user response:
you have to access the value of the array by the index number, try to modify this line:
console.log(greetReply[reply])
CodePudding user response:
reply is a random index from greetReply
to get value of that index use it
this way greetReply[reply]