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

clifford dsouza
seal-mask
.a{fill-rule:evenodd;}techdegree
clifford dsouza
Full Stack JavaScript Techdegree Student 1,755 Points

Inside the sayHi() function, add the code to make an alert dialogue appear with the word "Hi" in it.

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

2 Answers

Daniel Riches
Daniel Riches
19,847 Points

You created the function skeleton correctly. function sayHi(){} inside the function, you don't need the variable const Hi. If you do want to use it, just make it's value the string you want to display in the alert. The alert() takes a parameter of what is to be said. So for instance, a string: alert("What's up, doc?"); or if you want to use the variable Hi, i.e. const Hi = "What's up, doc?"; then just put that in the alert(Hi)

Then you call the function outside of the function, by typing the name of the function followed by parentheses.

function myFunction () {

// block of code goes here

}

// call function here

myFunction();

Hello! please is there anyone help me for this question Inside the sayHi() function, add the code to make an alert dialogue appear with the word "Hi" in it.

Daniel Riches
Daniel Riches
19,847 Points

Not certain where the original problem comes from, but here is one way to do it.

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

sayHi();