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.

3 Likes

Thanks, you too. :slight_smile: .

2 Likes

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.

2 Likes

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++) {
  functionName()
}

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
}

greetUser();