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

200
Views
How can I create a method to /2 the array

I am learning to code and I am trying out this javascript object method course. I am currently stuck on this method. I want to have the array with three different numbers(2,5,10) to be /2. I do not understand why it is returning NaN. Thank you for reading.

//Eggs hatch time
eggHatchTime2km = 2
eggHatchTime5km = 5
eggHatchTime10km = 10

allEggsTime = [eggHatchTime2km,eggHatchTime5km,eggHatchTime10km];
console.log(allEggsTime); //reads out 2,5,10

const pokemonGoCommunityDay = {
  eventBonuses: {
    calculateEggHatchTime() {
      return allEggsTime/2; //return NaN
      //return eggHatchTime2km,eggHatchTime5km,eggHatchTime10km/2; //return the value of the last variable(10km) but not 2km and 5km

    },
  }
}

console.log(pokemonGoCommunityDay);
console.log(pokemonGoCommunityDay.eventBonuses.calculateEggHatchTime());
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try using .map()

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

const pokemonGoCommunityDay = {
    eventBonuses: {
        calculateEggHatchTime() {
            const halfEggsTime = allEggsTime.map(egg=>egg/2)
            return halfEggsTime;
        }
    }
}
about 4 years ago · Juan Pablo Isaza Report

0

Maybe try .forEach to apply the same function to each element in an array

const pokemonGoCommunityDay = {
    eventBonuses: {
        calculateEggHatchTime() {
            const halfEggsTime = allEggsTime.forEach(egg=>egg/2)
            return halfEggsTime;
        }
    }
}

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

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!