String not exact?

Hi there! My code seems to be correct and the program is running as it should, but it won’t complete the exercise for me, and I keep getting a message in red saying this:

If the planet passed as an argument is anything other than the Mercury, Venus, Mars, Jupiter or Saturn, your function should return: ‘Invalid Planet Entry. Try: Mercury, Venus, Mars, Jupiter, or Saturn.’ : expected ‘Invalid Planet Entry. Try: Mercury, Venus, Mars, Jupiter, or Saturn’ to equal ‘Invalid Planet Entry. Try…

The thing is, when I do pass an argument other than Mercury, Venus, Mars, Jupiter, or Saturn, the function returns the correct error message. What am I missing?

the return message has to be identical, copy paste it from the instructions (to eliminate typos)

1 Like

Sidebar to that would be the evolution of fewer commas mentality of modern grammar which proposes the comma in question is overkill and not needed. The member’s code was perfectly compliant with that notion. Might need to employ a grammarian to oversee narratives and SCT requirements.

1 Like

Why can’t I go to the next exercise? I get this error: “If the planet passed as an argument is anything other than the Mercury, Venus, Mars, Jupiter or Saturn, your function should return: ‘Invalid Planet Entry. Try: Mercury, Venus, Mars, Jupiter, or Saturn.’ : expected ‘Invalid Planet Entry. Try: Mercury, Venus, Mars, Jupiter or Saturn.’ to equal ‘Invalid Planet Entry. Try”

This is my code:

// Write your function here:
const calculateWeight = (earthWeight, planet) => {
  switch (planet) {
    case 'Mercury':
    	return earthWeight * .378;
    case 'Venus':
   	  return earthWeight * .907;
    case 'Mars':
    	return earthWeight * .377;
    case 'Jupiter':
    	return earthWeight * 2.36;
    case 'Saturn':
    	return earthWeight * .916;
    default:
    	return 'Invalid Planet Entry. Try: Mercury, Venus, Mars, Jupiter or Saturn.';
  }; //closes planet switch
}; // closes calculateWeight
  
console.log(calculateWeight(82, 'Mars'));

// 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!

Missing comma before or Saturn.

Hi! i’m in stuck another time again!
i’ve write the code correctly and it’s work but the control exercise tell me that it’s wrong. why?
it’s frustrating learn in this way.
can someone explain to me what i’ve do wrong here?
thank you

const calculateWeight = (earthWeight, planet) => {

  switch (planet) {
    case 'Mercury': 
      return earthWeight*.378;
    case 'Venus':
      return earthWeight*.907;
    case 'Mars':
            return earthWeight*.377;
    case 'Jupiter':
            return earthWeight*2.36;
    case 'Saturn':
            return earthWeight*.916;
    default:
      return 'Invalid Planet Entry. Try: Mercury, Venus, Mars, Jupiter, or Saturn';
  }
};

for the default, the string returned should be an exact match. Just copy paste it from the instructions

thank you, now i know.
in future i will do .

This way, you make things a lot easier for yourself. Like you said, it should not be a focus point

Man its always a small typo somewhere! I had a long question written out to ask you guys to inspect my code, but when I copy/pasted my code at the bottom of the post, the spell check underlined one line of earthWeight, where I switched out an 'I" and an 'E" . Is it usually the case that its a small typo that throws an error rather than bad logic?

maybe in the beginning? I think with more experience in the errors you will more quickly filter out typo errors you make. The codecademy lessons are sometimes also quite unforgiving (a string returned by a function needs to be an exact match for example)

It also depends, the IDE uses spell checking. Quite handy to prevent typos.

1 Like

Thanks @stetim94 glad to know that I (hopefully) will grow out of it.