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

Zachary Pratt
Zachary Pratt
2,395 Points

Communication Problems

How do I get pass this problem, that I have been experiencing for the last 24 hrs? I get through the first and second challenge questions and on the third; I get the problem popup.

script.js
function sayHi() {
  alert('Hi');
  sayHi();
}
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

Colin Marshall
Colin Marshall
32,861 Points

Your problem is that you are calling the sayHi() function inside of itself. Move the function call to outside of the function and you will be good to go.

Jake Lundberg
Jake Lundberg
13,965 Points

You need to call the function outside the code block. So:

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

sayHi();

jake you forgot to close you initial function.

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

// calling the function here sayHi();

Colin Marshall
Colin Marshall
32,861 Points

Jake's code is correct. It might look funny because it's all on one line, so I'm going to fix that for him.

Jake Lundberg
Jake Lundberg
13,965 Points

What do you mean...both curly braces are there....?

Jake Lundberg
Jake Lundberg
13,965 Points

lol thanks Collin...I always forget to do that.

Sorry about that, I thought the function required a semi-colin

Its because you are calling the function inside the function. call the function outside of the brackets and you should be good to go.