Am asking to understand why

why is it that this code failed to run when i used different variable name from the function declared name


function orbitalPeriod(arr) {
// giving vaues of the earth setted to constant
const GM = 398600.4418;
const earthRadius = 6367.4447;

// reading through the arr using map method to return with function with parameter of name and avgAlt
return arr.map(({name, avgAlt}) => {

// adding together the radius of the earth with the average altitude
const earth = earthRadius + avgAlt;
// create rouded orbital Period, which will be used to replace the position of avgAlt in question 
const orbitalPrd = Math.round(2 * Math.PI * Math.sqrt(Math.pow(earth, 3) / GM));
return {name, orbitalPrd};
});
}

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

  **but this one worked out very well** :point_down: :point_down:

function orbitalPeriod(arr) {
// giving vaues of the earth setted to constant
const GM = 398600.4418;
const earthRadius = 6367.4447;

// reading through the arr using map method to return with function with parameter of name and avgAlt
return arr.map(({name, avgAlt}) => {

// adding together the radius of the earth with the average altitude
const earth = earthRadius + avgAlt;
// create rouded orbital Period, which will be used to replace the position of avgAlt in question 
const orbitalPeriod = Math.round(2 * Math.PI * Math.sqrt(Math.pow(earth, 3) / GM));
return {name,  orbitalPeriod};
});
}

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

so i want to know why it didnt worked out as i expected it to do. concerning the orbitalPrd that didnt work, and orbitalPeriod that worked
thank you

It has nothing to do with function name, but with the expected answer format: an array with objects that have name and orbitalPeriod keys. In your first example you’re using ES6 shorthand in return:

return { name, orbitalPrd }

which translates to:

return { name: name, orbitalPrd: orbitalPrd }

If you wan’t to use orbitalPrd, then your return should be:

return { name, orbitalPeriod: orbitalPrd }
3 Likes

i catch it now. :+1: