JAVA - calculateWeight()

I tried to use if, else if and else to finish this qustion.
However, it is showing undefined.
Pls helpppp.

// Write your function here:
const calculateWeight=(earthWeight,planet)=>{
if  (planet='Mercury'){


return

earthWeight * 0.378
}

else if  (planet='Venus'){
return 

earthWeight * 0.907
}
else if  (planet='Mars'){
return 

earthWeight * 0.377
}
else if  (planet='Jupiter'){
return 

earthWeight *  2.36
}
else if  (planet='Saturn'){
return 

earthWeight * 0.916
}
else {
  return 
  'Invalid Planet Entry. Try: Mercury, Venus, Mars, Jupiter, or Saturn.'}

}
console.log(calculateWeight(100, 'Jupiter'));






// Uncomment the line below when you're ready to try out your function
// console.log(calculateWeight(100, 'Jupiter')) // Should print 236

// We encourage you to add more function calls of your own to test your code!```

note that (planet='Mercury') should be (planet === 'Mercury') because === or == are used to check whether things are equal. The = is used to assign a value to something.

Also, in JavaScript the return must be on the same line as what you’re returning’
so

return

earthWeight * 0.378

should be

return earthWeight * 0.378;
1 Like