0

I'm doing this challenge incrementally so not all the code will be functional, but I've isolated an issue so far. I don't know how to retrieve the value of a key by the key's name. So if the input is mercury, I want to retrieve 0.2408467 by using the string 'mercury' as an argument. Here's my JS:

var spaceAges = {
  earth: 1,
  mercury: 0.2408467,
  venus: 0.61519726,
  mars: 1.8808158,
  jupiter: 11.862615,
  saturn: 29.447498,
  uranus: 84.016846,
  neptune: 164.79132,
}

function getSpaceAge(seconds, planet) {
  //var earthYears = seconds / 31536000;
  var x = spaceAges['planet'].value;
  console.log(x);
}

getSpaceAge(2134835688, mercury);
mplungjan
  • 169,008
  • 28
  • 173
  • 236
rook218
  • 644
  • 7
  • 20

0 Answers0