Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables Create a Variable

what am i doing wrong over here over on the java script side

i tried modifying it but nothing have changed

scripts.js
var myName();
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="scripts.js"></script>
</body>
</html>

3 Answers

Adam Moore
Adam Moore
21,956 Points

You're variable is using parentheses, but you only use those for functions. Therefore, you simply need to write the keyword "var" and then whatever you are going to name the variable, followed simply by a semicolon.

Ferdinand Pretorius
Ferdinand Pretorius
18,705 Points

Hi Ammar,

You literally only need the following code.

var myName;

That is how you initialize a variable without assigning it a value.

Good luck!

You have method myName() referenced as a variable.

Create the function you want to invoke, then if you wish you can reference it via a var.

So:

function myName(){ alert('Hey my name is yadada'); }

var name = myName();

Or programmatically:

function myName(name){ alert('Hey my name is ' + name); }

myName('yadada');

Or if you want to reference it as a variable object:

var thisIsMyName = function myName(name){ alert('Hey my name is ' + name); }

thisIsMyName.myName('yadada');