Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
Why reply variable is giving index number of greetReply array? I want the value from that array

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)
        }
    }
})

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you have to access the value of the array by the index number, try to modify this line:

console.log(greetReply[reply])

about 4 years ago · Juan Pablo Isaza Report

0

reply is a random index from greetReply to get value of that index use it this way greetReply[reply]

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!