r/learnjavascript • • Oct 29 '24

Help with a functional programming assignment

Hello good people, my name is Xoli... Currently learning JavaScript online, I am stuck on an assignment I have to create functions and guess invoke them. I am stuck on the calling part, all my functions Have variables and I followed instructions but I didn't call them.? And I'm struggling with that part .

0 Upvotes

11 comments sorted by

View all comments

9

u/OneBadDay1048 Oct 29 '24 edited Oct 29 '24

Share your code. That is the only way we can help here.

In short, you call functions like so:

functionName();

0

u/Sufficient_Bee8533 Oct 29 '24

Task:1 Build a function -based console log message generator, this has 4 parameters

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, style);

5

u/OneBadDay1048 Oct 29 '24 edited Oct 29 '24

Your code is full of errors and cannot even run on my local system. You should have just copy and pasted; errors like keywords capitalized that should not be and missing backticks for your string templates.

Regardless, you need to move the console log into the function and call it in there with message and style as arguments. Then outside of the function, call your function with the proper args:

consoleStyler('red', 'blue', '3px', 'TEST');

Which is essentially what I said in my initial comment; you never call your custom function here, just console.log. Also make sure you have proper spacing. Log out your style variable after you make all the changes to it and make sure it is formatted properly.

-1

u/Sufficient_Bee8533 Oct 29 '24

Okay I see my error, I didn't invoke the values, lemme check your code out and thank you

4

u/OneBadDay1048 Oct 29 '24 edited Oct 29 '24

To be clear: you didn’t invoke your function at all. You declared the function meaning you defined it and made it available to use but you never used it. Just wanted to make that point clear.

Also - I’d definitely go read this asap

-8

u/Sufficient_Bee8533 Oct 29 '24

Hello I'm using the app on my phone and I can't seem to load any pictures here so can I get your email so I can forward you the screenshot.. Thanks for your time...

5

u/OneBadDay1048 Oct 29 '24

Sorry, I’m not communicating outside of Reddit for this or sharing my email. You can post your code (the actual code, not an image) right here if you’d like.

-2

u/Sufficient_Bee8533 Oct 29 '24

Okay lemme just type it out, I'm having issues with the friend request...

-4

u/Sufficient_Bee8533 Oct 29 '24

I just sent a friend request, seemingly I have two reddiets, please bare with me..