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 Creating a Function

Call the new say Hi function you just created!

Totaly lost on this one guy's.

script.js
function sayHi(); {
alert ('Hi');
alert ('Say Hi')  
}
index.html
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

3 Answers

Robert Bennett
Robert Bennett
11,927 Points

You almost got it... Here is the trick - you are calling the function which means you are calling the name of the function which is sayHi() pretty easy? But where do you call the function? You call the function sayHi() after the braces. If you called the function in the braces you would call it onto itself and the function won't work. But calling it after the braces gets it out of its scope. Here is the code which is close to yours but I called it after the braces.

function sayHi() { alert("Hi") } sayHi();

I tried that Robert and it still doesn't work!

Robert Bennett
Robert Bennett
11,927 Points

I tried that code and it worked for me. function sayHi() { alert("Hi") } sayHi();

Cool thanks Robert! I accidentally put in the semi colon after the sayHi(); function. Cheers!

Robert Bennett
Robert Bennett
11,927 Points

OK.. Keep on coding and never give up!!!

function sayHi() { alert("Hi") } sayHi();