• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

281
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

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error