Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Review Creating Reusable Code with Functions

Need help!!

Given this function, write the code to call it: function warning() { alert('Warning, warning, warning!'); }

this is a question how you will call it?

4 Answers

Julie Myers
Julie Myers
7,627 Points
// This is your function. It is waiting in memory to be called so it can be executed/run.
function warning() { 
  alert('Warning, warning, warning!'); 
}

// This is how you call a function:
warning();

/*
Let's take the function call apart: warning();
+ warning is the name of the function. You have to tell javaScript which function you want to call.
+ () is an operator. This () operator is a function itself under the hood which does all the work of  finding the function in memory and getting the function to execute it's coding.
+ ; is the semi-colon. Always use a semi-colon at the end to let javaScript know you are done with your statement. It is considered best coding practice.
*/
Erik S.
Erik S.
9,789 Points

Hi, you can call the function just by typing it out:

warning();

You can leave the brackets empty in this case.

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

The answer is:

warning()

Leave out the semi-colon because that is already at the end of the line that you write in, other wise you would add that.

Frederic Soloy
Frederic Soloy
10,861 Points

Hi mhammad hamza. The answer is in your question; your function name is 'warning' so start with that: 'warning.call();' This is the method to call a function. Good luck.