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?
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.
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!
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';
}
};
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.
I must say it is quite frustrating that the string has to be an exact match. It has no relevance whatsoever to writing syntactically correct code that works. It only frustrates coding newbies like myself because I am focusing on writing correct code that follows the rules rather than an out of place comma in a string that is for display purposes only. Can’t you release the brakes on this a bit? I think it would make for a better user experience with your platform.
Being lenient is how you get horrible things like javascript.
Oh this is about javascript.
Lenient is just another way of saying it’s not doing what you said.
If things don’t do as you say it gets difficult to get things to happen as you say. This is bad. It should do what you said. It should be exact.
It helps to expect to need to produce exact results, because then you can check whether you did.
This seems to be a case where you get told both strings, if you’re told that two things are different, compare them, don’t go “hey they look about the same”
For example, take a look at semi-colons. JavaScript is lenient about those. Most beginners (unless being diciplined about it) will sprinkle semicolons all around and javascript won’t complain regardless of whether it’s missing or redundant. You’re probably experiencing this first hand. That’s what leniency gets you.