Practice JavaScript conditionals and functions with these 3 code challenges

Hi,
Please help.
When I do RUN it works.
When I do Check Answer I see ERROR

function colorMessage(favoriteColor, shirtColor) {
if (favoriteColor === shirtColor) {
return ‘The shirt is your favorite color!’;
} else {
return ‘That is a nice color.’; }}
console.log(colorMessage(‘black’, ‘white’));

BR
Nikolay

Hey,
Welcome to the forums. There was one tiny error you made throughout your code. You used ‘ instead of '. You probably can’t see it in this post since it’s so small, but a string in JavaScript should be yellow. If it’s red take that as a sign that it’s not been recognised as a string. JavaScript in this case doesn’t recognise your strings as strings because you’re not using the right quotation marks.

What you used is a single left quote. You should either use ` ’ or " to create strings. Backtick, single quotes or double quotes. Your code should look like the following. Paste it into your code so you can see what’s been changed.

function colorMessage(favoriteColor, shirtColor) {

  if (favoriteColor === shirtColor) {
    return 'The shirt is your favorite color!';
} else {
  return 'That is a nice color.'; }}
console.log(colorMessage('black', 'black'));

Hope this helps. If not don’t hesitate to ask for more help.

2 Likes

I am guessing that the reason the quotation marks are not showing up correctly in your post is that you pasted the code in this forum. If you instead press the little </> symbol when posting and paste JS code between the backticks, it will be recognized as JS code. This helps a lot in this forum.

I also did this exercise the other day and I think there is an error in the test for the colorMessage function. I submitted a bug-report as my code worked fine when I ran it in the console but still did not pass the test.

2 Likes

Could you post a link to the exercise please? As chances are that @mike7127143742 is right-you have the correct quotation marks, but when you copy/paste it into the forums, they are automatically changed to “smart quotations”.

3 Likes

Link to exercise
https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-i/modules/fecp-practice-javascript-syntax-variables-data-types-conditionals-functions/articles/fecp-javascript-practice-data-types-conditional-functions
Quotation marks is ok in exercise. They changed after paste it into forum.


Can you see attached screenshot?

1 Like