Map the debris - what is wrong here

Tell us what’s happening:
The output of my function looks correct to me, but I’m failing the second test. Am I missing something obvious? I can’t tell what is wrong on my code.

  **Your code so far**

function orbitalPeriod(arr) {
var GM = 398600.4418;
var earthRadius = 6367.4447;

function objPeriod(altitude) {
      return Math.round((Math.sqrt(Math.pow((earthRadius + altitude), 3) / GM)) * 2 * 3.14159)
  }

return arr.map(obj =>({name: obj.name, orbitalPeriod: objPeriod(obj.avgAlt)}));
}

orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:78.0) Gecko/20100101 Firefox/78.0.

Challenge: Map the Debris

Link to the challenge:

Nevermind, I think I got it. My function returns an object, whereas it should return an array.

Nope, I was wrong, my function returns an array as expected. Still haven’t a clue of what is wrong. I could really use an hint, don’t want to look at the solution yet. Thanks!

the expected is

[{name : "iss", orbitalPeriod: 5557}, {name: "hubble", orbitalPeriod: 5734}, {name: "moon", orbitalPeriod: 2377399}]

your output is

[ { name: 'iss', orbitalPeriod: 5557 },
  { name: 'hubble', orbitalPeriod: 5734 },
  { name: 'moon', orbitalPeriod: 2377397 } ]

the last digit of the moon period is wrong - this is a maths issue, your PI has 6 significant digits, meaning it will give only 6 significant digit to your result - the moon period has 7 digits, outside of that safe range of 6 digits and in fact the last digit is the wrong one.

I suggest
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI

1 Like

:sweat:
I guess I wasn’t paying attention enough. I did try to search for a PI constant but I didn’t think to search in Math. functions.
Thank you ieahleen.

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