FAQ: Functions - Calling a Function

This community-built FAQ covers the “Calling a Function” exercise from the lesson “Functions”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise Calling a Function

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

On page 3 of 11, there seems to be a broken image tag. After the sentence “This function call executes the function body, or all of the statements between the curly braces in the function declaration.”, the following appears next to an empty white square: “Function execution diagram”

3 Likes

I think this is the image:

3 Likes

Thanks for posting the diagram. Mine appears as just an empty square too. I’m using Chrome browser - do you think it could be a browser compatibility issue? How did you get the image to appear?.. or do you have a separate, secret source? :wink: )

https://s3.amazonaws.com/codecademy-content/courses/learn-javascript-functions/Diagram/function+execution.svg

try updating your Chrome

It worked fine for me on Firefox. But it would help if Codecademy could magnify the image on this exercise and the next. It required some mighty squinting (and zooming in) on my laptop to see everything properly.

chrome_hfppbqgB9O

What am I doing wrong here?

1 Like

I had the same problem today. I did not understand what the mistake was. When I received the solution, I found no difference.

Is there any way to call a function multiple times without manually calling it over and over again? Is there some sort of math feature?

2 Likes

How is this different from a variable apart from the syntax. I mean this ‘Function’ is also storing information right?

Hmm, maybe try a semicolon at the end of line #2.

This is good, but, this is doing a just a console.log three times, how can i do a comand to repeat the same action three times without need to write it three time? Any function for that?

(I’m quite new in learning how to code! ha!)

Here you go.

function sayThanks()
{
  console.log("Thank you for your purchase! We appreciate your business.");
}

var i = 1;
while (i <= 3)
{
  sayThanks();
  i++;
}

But is this the most optimal way to do it?

What about a for loop?

for(var i = 0; i < 3; i++) {
  console.log("Hello");
}

Wouldn’t that be more efficent?

At this point? From what I’ve read, probably not much difference. If you’re coding enterprise stuff then the for loop might gain you a couple of ticks depending on the compiler.

More efficient though, and you don’t have an extra global variable.

1 Like

All righty. If you say so. :slight_smile:

Haha, don’t say that. What if I’m completely wrong? Defend your position!

Why do you think a while loop is better for the task?

I don’t think that a while loop is better for the task. I think that, in terms of program efficiency, (speed at runtime), the while loop and the for loop will perform the same.

Also, if you’re declaring i outside of the encompassing function block, (making it global in scope), for either the while or for loop, then you’re not following generally-accepted best practices. The i from neither the for nor while loop should live to see the outside of the function it’s in.

1 Like

Hrm, that’s a good point. Is there any reason at all that you used a while loop instead of a for loop?