Intermediate Algorithm Scripting - Map the Debris

Tell us what’s happening:
Describe your issue in detail here.
Why orbit is NaN
Your code so far

function orbitalPeriod(arr) {
  const GM = 398600.4418;
  const earthRadius = 6367.4447;
  let newArr = [],
      values = arr.map(el => Object.values(el)).flat(),
      avg = 0

for (let i=0; i<values.length; i++) {
  if (typeof values[i] === "number") {
    avg = values[i]
  }
}

//T = 2 * pi * sqrt((earthRadius + avgAlt)^3 / GM)


  let orbit = Math.round(2 * Math.PI * Math.pow(Math.sqrt(earthRadius + avg)) / GM)

 newArr.push({name: values[0], orbitalPeriod: orbit})

 return newArr

}

console.log(orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]));

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 11; Nokia 3.4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Mobile Safari/537.36

Challenge: Intermediate Algorithm Scripting - Map the Debris

Link to the challenge:

Try splitting the orbit assignment to pinpoint the exact place NaN appears. For example:

const orbit = 2 * Math.PI * Math.pow(Math.sqrt(earthRadius + avg)) / GM;
console.log(orbit);
const orbitRounded = Math.round(orbit);
console.log(orbitRounded)

I skipped the number 3 thanks

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.