Coursera challenge error

I have typed the code for the tasks and also got the output but still i got 25 marks in coursera challenge. Please let me know if anyone can solve this for me.
I have jotted down tasks, my code, output and the reason for failing the tasks.

These are the tasks

Task 1: Build a function-based console log message generator

In this exercise, your task is to code a function named consoleStyler, which accepts four parameters:

  • color
  • background
  • fontSize
  • txt

Inside the body of the consoleStyler() function declaration, you need to do the following:

  1. Create a new variable named message, and assign the following to it on the very first line inside the consoleStyler() function body.:

    "%c" + txt;
    
  2. Create a style variable and assign the following to it on the next line:

    `color: ${color};`
    
  3. Next, update the style variable (using the += operator) with the following code:

    `background: ${background};`
    
  4. Then, update the style variable (again, using the += operator) with the following code:

    `font-size: ${fontSize};`
    
  5. Finally, console log the message and style variables inside the consoleStyler function declaration.

Hint: Be sure to use backticks (``) when updating your variable styles and not single (‘’) or double (“”) quotes.


Task 2: Build another console log message generator.

Your task is to code another function, and name it celebrateStyler(). The function accepts a single parameter, reason, which should be of string data type.

Inside the function declaration’s body, code the following:

  1. A new variable, named fontStyle, assigning it this code:

    "color: tomato; font-size: 50px";
    
  2. On the next line, an if statement, verifying that reason == "birthday".

  3. Inside the body of the if block, code the following:

    console.log(`%cHappy birthday`, fontStyle);
    
  4. On the next line, add an else if, and inside the parentheses, check that

    reason == "champions"
    
  5. Inside the else if block, add this code:

    console.log(`%cCongrats on the title!`, fontStyle);
    
  6. Add an else block, with the following code inside of it:

    console.log(message, style);
    

Task 3: Run both the consoleStyler and the celebrateStyler functions

  1. Invoke the consoleStyler() function, with the following arguments:

    • '#1d5c63'

    • '#ede6db'

    • '40px'

    • 'Congrats!'

  2. Next, invoke the celebrateStyler() function, with the following argument:

    • 'birthday'

Task 4: Insert a congratulatory and custom message

  1. Code another function, named styleAndCelebrate().
    The function declaration’s body should consist of two function invocations:

    consoleStyler(color, background, fontSize, txt);  
    celebrateStyler(reason);
    
  2. Next, invoke the new function, using the following arguments:

    • 'ef7c8e'
    • 'fae8e0'
    • '30px'
    • 'You made it!'
    • 'champions'

This is my code

function consoleStyler(color, background, fontSize, txt){
    var message = "%c" + txt;
    var style = `color: ${color}`;
    style += `background: ${background}`;
    style += `font-size: ${fontSize}`;
    console.log(message);
    console.log(style);
}

function celebrateStyler(reason)
{
    var fontStyle = "color: tomato; font-size: 50px";
    if (reason == "birthday")
    {
        console.log(`%cHappy birthday`, fontStyle);
    }
    else if (reason == "champions")
    {
        console.log(`%cCongrats on the title!`, fontStyle);
    }
    else
    {
        console.log(message, style);
    }
}

consoleStyler('#1d5c63', '#ede6db', '40px', 'Congrats!');
celebrateStyler('birthday');

function styleAndCelebrate(color, background, fontSize, txt, reason)
{

    consoleStyler(color, background, fontSize, txt);
    celebrateStyler(reason);
}

styleAndCelebrate( '#ef7c8e','#fae8e0','30px','You made it!','champions');

Output :

%cCongrats!
color: #1d5c63background: #ede6dbfont-size: 40px
Happy birthday
%cYou made it!
color: #ef7c8ebackground: #fae8e0font-size: 30px
Congrats on the title!

But Coursera showing me this
Failed Test 1: Not logging the consoleStyler() variables
Passed Test 2: successfully logged celebrateStyler() variables
Failed Test 3: Not calling consoleStyler() and celebrateStyler()
Failed Test 4: Not calling styleAndCelebrate()

@ilenia you edited the post. But i can’t find the solution. It shoes you only removed back ticks

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

okay, thank you for the information

I’m facing the same problem and don’t understand what to do please help someone.

Actually it’s the problem of the Coursera Lab. Even if your code is correct it shows error. Try removing semicolons and var keyword.Sometimes it works sometimes doesn’t If it doesn’t helps, I will share you my code.

it’s still showing error pls share your code!

// Task 1: Build a function-based console log message generator
function consoleStyler(color, background, fontSize, txt) {
message = “%c” + txt;
style = color: ${color};;
style += background: ${background};;
style += font-size: ${fontSize};;
console.log(message, style);

}

// Task 2: Build another console log message generator
function celebrateStyler(reason) {
fontStyle = “color: tomato; font-size: 50px”;
if (reason == “birthday”) {
console.log(%cHappy birthday, fontStyle);
} else if (reason == “champions”) {
console.log(%cCongrats on the title!, fontStyle);
} else {
console.log(message, style);
}
}

// Task 3: Run both the consoleStyler and the celebrateStyler functions
consoleStyler(‘#1d5c63’, ‘#ede6db’, ‘40px’, ‘Congrats!’);
celebrateStyler(‘birthday’);

// Task 4: Insert a congratulatory and custom message
function styleAndCelebrate(color, background, fontSize, txt, reason) {
consoleStyler(color, background, fontSize, txt);
celebrateStyler(reason);
}
// Call styleAndCelebrate

styleAndCelebrate(‘#ef7c8e’, ‘#fae8e0’, ‘30px’, ‘You made it!’, ‘champions’);

Thanks, Nishant for helping me, I was stuck in this circle since morning

1 Like

Here is you problem, just syntax Error.

In Task 1 you put the back-ticks before the semi -colon that’s why your variables are logging…that’s why it affected both task 3 and 4

see my example below…

// Task 1: Build a function-based console log message generator
function consoleStyler(color, background, fontSize, txt) {
    var message = "%c" + txt;
    var style = `color: ${color};` 
    style += `background: ${background};`
    style += `font-size: ${fontSize};`
  
    console.log(message, style);

}

// Task 2: Build another console log message generator
function celebrateStyler(reason) {
    var fontStyle = "color: tomato; font-size: 50px";
     if(reason == "birthday"){
        console.log(`%cHappy birthday`, fontStyle);
     } else if(reason == "champions"){
        console.log(`%cCongrats on the title!`, fontStyle);
     } else {
        console.log(message, style);
     }
}

// Task 3: Run both the consoleStyler and the celebrateStyler functions
consoleStyler('#1d5c63', '#ede6db', '40px',  'Congrats!');
celebrateStyler('birthday');

// Task 4: Insert a congratulatory and custom message
function styleAndCelebrate(color, background, fontSize, txt, reason) {
    consoleStyler(color, background, fontSize, txt);  
    celebrateStyler(reason);

}

// Call styleAndCelebrate
styleAndCelebrate ('ef7c8e', 'fae8e0', '30px','You made it!', 'champions');

3 Likes

i feel this was the best solution so far, not the kind that believes in the examiner being wrong so quickly, although, it tickled my brain for the whole day, but i really learnt alot, thank you very much

Thanks guys for helping also i forget to console.log in one line in task one so i got error, but resolve now reading your provided solution thanks for sharing.

in any case any one facing here is my code …

// Task 1: Build a function-based console log message generator
function consoleStyler(color, background, fontSize, txt) {
  var message = "%c" + txt;
  var style = `color: ${color};`;
  style += `background: ${background};`;
  style += `font-size: ${fontSize};`;
  console.log(message, style);
}
// Task 2: Build another console log message generator
function celebrateStyler(reason) {
 var fontStyle = "color: tomato; font-size: 50px";
  if (reason == "birthday") {
    console.log(`%cHappy birthday`, fontStyle);
  } else if (reason == "champions") {
    console.log(`%cCongrats on the title!`, fontStyle);
  } else {
    console.log(message, style);
  }
}

// Task 3: Run both the consoleStyler and the celebrateStyler functions

consoleStyler("#1d5c63", "#ede6db", "40px", "Congrats!");
celebrateStyler("birthday");
// Task 4: Insert a congratulatory and custom message
function styleAndCelebrate(color, background, fontSize, txt, reason) {
  consoleStyler(color, background, fontSize, txt);
  celebrateStyler(reason);
}
// Call styleAndCelebrate

styleAndCelebrate("#ef7c8e", "#fae8e0", "30px", "You made it!", "champions");

// Task 1: Build a function-based console log message generator

function consoleStyler(color, background, fontSize, txt) {
var message = “%c” + txt;
var style = color: ${color};
style += background: ${background};
style += font-size: ${fontSize};

console.log(message, style);

}

// Task 2: Build another console log message generator
function celebrateStyler(reason) {
var fontStyle = “color: tomato; font-size: 50px”;
if(reason == “birthday”){
console.log(%cHappy birthday, fontStyle);
} else if(reason == “champions”){
console.log(%cCongrats on the title!, fontStyle);
} else {
console.log(message, style);
}
}

// Task 3: Run both the consoleStyler and the celebrateStyler functions
consoleStyler(‘#1d5c63’, ‘#ede6db’, ‘40px’, ‘Congrats!’);
celebrateStyler(‘birthday’);

// Task 4: Insert a congratulatory and custom message
function styleAndCelebrate(color, background, fontSize, txt, reason) {
consoleStyler(color, background, fontSize, txt);
celebrateStyler(reason);

}
// Call styleAndCelebrate
styleAndCelebrate (‘ef7c8e’, ‘fae8e0’, ‘30px’,‘You made it!’, ‘champions’);

THANKS A LOT DUDE!!!

The solution proposed in this thread didn’t work for me, I got a 25/100.
I got a 100/100 with the following answer:

// Task 1: Build a function-based console log message generator
function consoleStyler(color, background, fontSize, txt) {
var message = “%c” + txt;
var style = color: ${color};
style += background: ${background};
style += font-size: ${fontSize};
console.log(message, style)
}

// Task 2: Build another console log message generator
function celebrateStyler(reason) {
var fontStyle = “color: tomato; font-size: 50px”
if (reason == “birthday”) {
console.log(%cHappy birthday, fontStyle)
} else if (reason == “champions”) {
console.log(%cCongrats on the title!, fontStyle)
} else {
console.log(“%c” + reason, fontStyle)
}
}

// Task 3: Run both the consoleStyler and the celebrateStyler functions
consoleStyler(‘#1d5c63’, ‘#ede6db’, ‘40px’, ‘Congrats!’)
celebrateStyler(‘birthday’)

// Task 4: Insert a congratulatory and custom message
function styleAndCelebrate(color, background, fontSize, txt, reason) {
consoleStyler(color, background, fontSize, txt)
celebrateStyler(reason)

}
// Call styleAndCelebrate

styleAndCelebrate(‘#1d5c63’, ‘#ede6db’, ‘40px’, ‘Congrats!’, ‘champions’)

bruh it failed me cuz i used ‘let’ instead of ‘var’ wtf

Well, if its not the VAR variables (Its not like you need it, since they are like global)
is the “;” at the end of each style.

function consoleStyler(color, background, fontSize, txt) {
message = “%c” + txt;
style = color : ${color};;
style += background: ${background};;
style += font-size: ${fontSize};;
console.log(message, style);
}

// Task 2: Build another console log message generator
function celebrateStyler(reason) {
fontStyle = “color: tomato; font-size: 50px”;
if (reason == “birthday”) {
console.log(‘%cHappy birthday’, fontStyle);
}
else if (reason == “champions”) {
console.log(‘%cCongrats on the title!’, fontStyle);
}
else {
console.log(message, style);
}
}
// Task 3: Run both the consoleStyler and the celebrateStyler functions
consoleStyler(‘#1d5c63’, ‘#ede6db’, ‘40px’, ‘Congrats!’);
celebrateStyler(‘birthday’);
// Task 4: Insert a congratulatory and custom message
function styleAndCelebrate(color, background, fontSize, txt, reason ) {
consoleStyler(color, background, fontSize, txt);
celebrateStyler(reason);
}
// Call styleAndCelebrate
styleAndCelebrate(‘ef7c8e’, ‘fae8e0’, ‘30px’, ‘You made it!’, ‘champions’);

I can’t figure out what is wrong with my code. When I run it I get the following output
Congrats!

Happy birthday

You made it!

Congrats on the title!
However when I submit it is giving me 25/100
pls help