FAQ: Functions - Calling a Function

Personal preference. I find for loops more difficult to “read” quickly. I’m still very much a beginner. I understand the syntax and use of both, though.

1 Like

Interesting. Anyways, thanks for the talk. You gave me something to think about.


Thanks, you too. :slight_smile: .


What’s the point of the parentheses after the function identifier?

Without the parentheses it doesn’t know to execute the function. If you try it without them, the console displays nothing.

why doesn’t sayThanks()*3 work for this exercise to print it 3 times? I’m sorry if I’m asking a dumb question.

Hey @design4906009099, welcome to the forums!
I would say this is because what you are trying to do by running this statement is multiple the output of the function by three. You aren’t making the function be called three times, you’re multiplying the output of the function by three.


That makes a lot of sense. Thank you for the help.

1 Like

You could use a loop. If you wanted to call a function 5 times, you could write it like this:

for (let i = 0; i < 6; i++) {

Yes. However, variables store values (1, "string", true, etc.) and functions store actions. If you wanted to store the user’s name somewhere, you would use a variable, and if you wanted to greet the user, you could use a function. If you only need to greet the user once, a function wouldn’t be necessary

const userName = prompt("What is your name?");

function greetUser() {
  console.log("Hello, " + userName); // Codecademy  doesn't allow backticks in forum posts


I just wanted to shared that if you do a while loop to say thanks 3 times it tells you that your code is wrong despite the console output being correct.

It would be nice if you could share your code. Sometimes, Codecademy does mess up, however, other times, it’s possible for you to have mistyped the string. This is why I recommend copy/pasting the string to make sure you don’t get e red cross


Am I missing something or is this a bug?

I’m running into that problem too. I think it’s probably the fact that for loops haven’t been introduced yet, and they don’t want you to use them until they are introduced. The way it is written works though.

hello I also ran into this problem could you tell me how you handled it

Right after sayThanks() you didn’t put a space between the () and the curly bracket “{”. That’s necessary I think.

I think these exercises need a quality check sometimes for purpose and usefulness. Asking me to write out sayThanks() 3 times just seems arbitrary and useless and it’s not what would be seen in real life. Surely here would be useful to implement that brackets () to thank 3 different customers sayThanks(Frank), sayThanks(Mary) etc…

No, I doubt it’s a bug. Some code just wants you to keep it simple for the moment and it’s designed to just look for sayThanks() just 3 times which equally seems kind of stupid and arbitrary.

You can try to replace the single quote ’ ’ with the back quote `` to wrap the message :joy:

I have just faced this issue and I resolved it by copy the exact string given in the left panel and past in console.loog()