Building a Functional Program using JavaScript

Can someone help me understand why I keep receiving these results? The code seems to run correctly and I don’t receive errors. The results say I’m not meeting the criteria but I’m not clear where.

Grading results:
image

// 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(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(‘ef7c8e’, ‘fae8e0’, ‘30px’, ‘You made it!’, ‘champions’);

Hello. Can we see the rest of your code, including the tests? And maybe some more context. And maybe you could put put this into a gist or something so we can get more information and some proper formatting? It would absolutely help.

Hi a2937, I provided the instructions for the assignment below. Hopefully this puts things into context. There isn’t any more code from what I provided. Please let me know if this still isn’t enough and I will try to provide more info. Thanks for your consideration

Lab Instructions: Building a Functional Program

In this exercise you’ll get hands-on practice with functional programming concepts.

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;

Tip: Do not copy the 3 back ticks. These are used to format this document in the Preview tab.
2. Create a style variable and assign the following to it on the next line:

`color: ${color};`

Tip: The single backtick before color and after the semi-colon must be included.
3. Next, update the style variable (using the += operator) with the following code:

`background: ${background};`

Tip: The single backtick before background and after the semi-colon must be included.
4. Then, update the style variable (again, using the += operator) with the following code:

`font-size: ${fontSize};`

Tip: The single backtick before font-size and after the semi-colon must be included.
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";
  1. On the next line, an if statement, verifying that reason == "birthday".
  2. Inside the body of the if block, code the following:
console.log(`%cHappy birthday`, fontStyle);
  1. On the next line, add an else if, and inside the parentheses, check that
reason == "champions"
  1. Inside the else if block, add this code:
console.log(`%cCongrats on the title!`, fontStyle);
  1. 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!'
  1. 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);
  1. Next, invoke the new function, using the following arguments:
  • 'ef7c8e'
  • 'fae8e0'
  • '30px'
  • 'You made it!'
  • 'champions'

Final Step: Let’s submit your code!

Nice work! To complete this assessment:

  1. Save your file through File → Save
  2. Select “Submit Assignment” in your Lab toolbar.

Your code will be autograded and return feedback shortly on the “Grades” tab.
You can also see your score in your Programming Assignment “My Submission” tab.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.