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

330
Views
if an array elements gets displayed using console.log() then why does it generate an error if we used the includes method on that array?

the code says :

function checkWinner(cellIndexes, machineAnswers) {
  console.log(
    `this is the cellIndexes array at the check winner function ${cellIndexes}`
  );
  console.log(
    `this is the cellIndexes array at the check winner function ${machineAnswers}`
  );

  if (
    cellIndexes.includes(1) &&
    cellIndexes.includes(2) &&
    cellIndexes.includes(3)
  )
    console.log("the user wins !!!");
  else if (
    cellIndexes.includes(4) &&
    cellIndexes.includes(5) &&
    cellIndexes.includes(6)
  )
    console.log("the user wins !!!");
  else if (
    machineAnswers.includes(1) &&
    machineAnswers.includes(2) &&
    machineAnswers.includes(3)
  )
    console.log("the computer wins wins !!!");
  else if (
    machineAnswer3.includes(4) &&
    machineAnswers.includes(5) &&
    machineAnswers.includes(6)
  )
    console.log("the computer wins !!!");
  else console.log("nobody won yet");
}

Even if I got in the console the elements of the two arrays cellIndexes and machineAnswers I still get an error saying

"index.js:1331 Uncaught TypeError: Cannot read properties of undefined (reading 'includes') at checkWinner "

These two arrays hold values so why are they being treated as un undefined variables at this function

about 4 years ago · Juan Pablo Isaza
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!