calculateWeight function

Hi there, i’m trying to do a codecademy challenges, and i dont get why it return undefined,
where ma i wrong?

function calculateWeight(earthWeight, planet){
planet = planet.toLowerCase();
if( planet === ‘Mercury’){

    return earthWeight * 0.378;

  } else if(planet === 'Jupiter'){

    return earthWeight * 2.36;// shou

console.log(calculateWeight(100, ‘Mercury’));

Within your function, you are converting the value assigned to planet to lowercase.

But, in your conditions, you are comparing this lowercase string with strings such as "Mercury" and "Jupiter".

Since a lowercase string will never match these strings, so none of the conditions is true and you exit the function without reaching any explicit return and therefore implicitly return undefined.

You could edit your conditions so that you are comparing the lowercase string to "mercury" and "jupiter" instead of "Mercury" and "Jupiter".

1 Like

thank you, i got it!. Even if i erase the planet declaration it is ok