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!

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 Functions Create Reusable Code with Functions Creating a Function

Creating a fuction

it's asking for the code needed inside the function that would make a dialogue appear. I've tried a few ways but idk.

function sayHi(){

  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="script.js"></script>

1 Answer

Nikos Papapetrou
Nikos Papapetrou
6,305 Points

You have created right an empty function as the 1st task of the challenge require. Then you have to write the code you want (inside the function code block) to be executed when you invoke the function.

function sayHello() {
     //my code here
     console.log('Hello there!');
//Here we only define the function and it is not being executed. So you will not see any result.

After you have define the function to see the result of your code you have to invoke the function- Function Invocation. To invoke a function you write the name of the function you have created and parenthesis:

//sayHello() will be executed and will appear in the console.

Thank You! This really cleared it up for me!