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) 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');