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

Rodrigo Alarcon
Rodrigo Alarcon
8,028 Points

what am i doing wrong?

it says to create a function called sayHi and not put anything inside, but to have the basic structure with an empty code block

script.js
function 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>

function sayHi (){}

don't add a semicolon

2 Answers

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

You're missing the curly braces.

You need opening and closing parentheses AND opening and closing curly braces. Inside the parentheses is where you would put any parameters. In this case there are none but you still need the empty parentheses. Inside the curly braces is where you're going to put the things that the function does.

function sayHi() {

}
Anand Mohan Duddella
PLUS
Anand Mohan Duddella
Courses Plus Student 8,264 Points

When you create a function like function sayHi(

); - You are invoking/calling a function before actually declaring it. To declare a function before calling it please use function sayHi (){

}

I hope then it should work and then you can call it as sayHi();