Map the Debris - Help needed :/

Map the Debris - Help needed :/
0

#1

Tell us what’s happening:

Can’t pass the challenge even though returned value is correct. I would really appreciate if someone could point out my mistake. Thanks!

Your code so far


function orbitalPeriod(arr) {
  var GM = 398600.4418;
  var earthRadius = 6367.4447;
	for (var i=0; i<arr.length; i++) {
  var a = arr[i].avgAlt + earthRadius;
  let periood = Math.round(Math.sqrt((Math.pow(a, 3) / GM)) * 2 * Math.PI);

  Object.defineProperty(arr[i], "orbitalPeriod", {
    value: periood
  });

  delete arr[i].avgAlt;  
	}
  
	console.log(arr);
  return arr;
}

orbitalPeriod([{name: "iss", avgAlt: 413.6}, {name: "hubble", avgAlt: 556.7}, {name: "moon", avgAlt: 378632.553}])
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}])

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris


#2

You’re missing the orbitalPeriod in your returned value.


#3

image

Thanks for the reply! Not sure what you mean exactly since the returned array has correct orbitalPeriod values according to console. The values in the pic are printed due to “console.log(arr)” at the end of the code.


#4

When I run the code that you provided above, I see only the names.


#5

I am actually super confused now.

If you look at the console of the link provided, you can see the correct returned values.

https://jsfiddle.net/snjegu/njwogurs/56/


#6

Something about the Object.defineProperty isn’t working. It may have to do with the code editor? (I say that because I think that FCC and repl.it both use tha manaco editor). If I change that to just

arr[i].orbitalPeriod = periood;

it works.


#7

Of course my solution was unnecessarily complicated, I forgot you can add properties this way as well. It’s strange that freecodecamp’s console printed the correct result with my original code. Oh well…

Anyways, thank you for your time :slight_smile:!