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

Janneke Polderman
Janneke Polderman
7,157 Points

Oops! It looks like Task 1 is no longer passing.

I get this error a lot, going through the different challenges. What am I doing wrong? In this case this is my code:

function sayHi(alert:"Hi") {

}

script.js
function sayHi(alert:"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>

2 Answers

andren
andren
28,558 Points

When you try to proceed to the next task / complete the challenge Treehouse usually runs a code checker that tries to verify that your code not only fulfills the criteria of the current task, but also fulfills the criteria of the previous tasks.

If your code contains a syntax error or something else that causes the code checker to crash then it won't be able to verify that your code passed the first task. Which is why it reports that there is an issue with task 1. Even if the code that causes the crash was written in a later task.

As for the issue with your code there are two of them:

  1. The alert is meant to be placed inside the body of the method. The body is the area between the opening curly brace "{" and closing curly brace "}". The area you put it in (within the parenthesis) is where you put parameters for the function. Which is something that will be explained later in the course.

  2. When you call a function you pass arguments by placing them inside parenthesis. You don't separate the function and the arguments with a colon like you have done with the alert function.

If you fix those two issues like this:

function sayHi() {
    alert("Hi"); // Alert was moved within body and had parenthesis added.
}

Then your code will work.