I was able to obtain the Orbital Period T in seconds and replace the aveAlt with orbitalPeriod and its associated value, but I’m struggling with how to iterate and replace aveAlt in an array with more than one Object. First test passes but second fails. I’ve tried using a for loop but haven’t had success yet…

Link to challenge:

Any leads would be appreciated.

function orbitalPeriod(arr) {
var GM = 398600.4418;
var earthRadius = 6367.4447;
function orbitalPeriodT ( arr ) {
let a = earthRadius + arr[0].avgAlt;
let aPow = (Math.pow(a, 3));
let SqaGM = Math.sqrt(aPow / GM);
let T = 2 * Math.PI * SqaGM;
return Math.round(T);
}
arr[0].orbitalPeriod = orbitalPeriodT(arr);
delete arr[0].avgAlt;
return arr;
}
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);

I removed the original for loop and am now trying a for in loop using arr[key], which seems to be giving me some results but haven’t worked it all out yet.

This is still a work in progress. I realize now I need to set arr[0] as arr[key].aveAlt and use it in a for loop along with the rest of the equations. This is what I am playing with. Doesn’t output anything yet. This is just adding the ability to see the aveAlt numbers in their own array. Since I can do that, I should be able to grab/loop through each arr[key].aveAlt number and then use it to solve for new number and re-insert somehow.

function orbitalPeriod(arr) {
var GM = 398600.4418;
var earthRadius = 6367.4447;
function orbitalPeriodT ( arr ) {
let a = earthRadius + arr[0].avgAlt;
let aPow = (Math.pow(a, 3));
let SqaGM = Math.sqrt(aPow / GM);
let T = 2 * Math.PI * SqaGM;
return Math.round(T);
}
let newArr = [];
for (let key in arr) {
arr[key].avgAlt;
newArr.push(arr[key].avgAlt);
}
console.log(newArr);
//return arr;
}