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 trialTony Bourne
2,432 PointsCall the new say Hi function you just created!
Totaly lost on this one guy's.
function sayHi(); {
alert ('Hi');
alert ('Say Hi')
}
<!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
11,927 PointsYou 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();
Robert Bennett
11,927 PointsOK.. Keep on coding and never give up!!!
Rashel Khan
1,351 Pointsfunction sayHi() { alert("Hi") } sayHi();
Tony Bourne
2,432 PointsTony Bourne
2,432 PointsI tried that Robert and it still doesn't work!
Robert Bennett
11,927 PointsRobert Bennett
11,927 PointsI tried that code and it worked for me. function sayHi() { alert("Hi") } sayHi();
Tony Bourne
2,432 PointsTony Bourne
2,432 PointsCool thanks Robert! I accidentally put in the semi colon after the sayHi(); function. Cheers!