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 trialmatt krempasky
490 Pointsi have tried to name my variable. it doesn't seem to be workingf var message = "myName" can you help?
i followed the naming the variable part in the video. tried a few different ways of naming
var message = ("myName")
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
var message = "myName";
<script src="scripts.js"></script>
</body>
</html>
4 Answers
Evgeniia Mas
4,452 PointsYou don't need braces and put a semicolon at the end like this: var message = "myName";
matt krempasky
490 Points<script> var name = "myname"; </script>
still says I'm wrong. re watched the video too. not sure what I'm doing wrong.
Evgeniia Mas
4,452 PointsIf you are doing the first part of challenge it asks you to set variable var myName = "Matt"; ok?
Larry Coonrod
5,041 PointsYou are trying to write the variable on the HTML page of the challenge. It needs to go on the script.js file. Look in the upper left hand corner of the challenge area. You'll see two tabs. Click on the"scripts.js."
var myName;
Jonathan Kuhl
26,133 PointsYou're doing a few things wrong.
First, you can't call naked JavaScript in the HTML file, it has to be between <script> tags or in its own .js file.
Second, within script.js, where you're setting the var message, you don't need the parenthesis and you must end it with a semicolon (get use to semi colons, especially if you move on to a language like C++.)
A variable is as follows, in most languages: type name = value In JavaScript, type is implicit (meaning the browser determines the type according to the value rather than the author) so we only use the keyword "var." The name is anything you want, according to JS's rules (review the video if you're not sure.) And the "=" is the assignment value, it gives a value to the variable. Assignment is optional if you're just declaring a variable. The value is a number or a string or a function.
So it should look like, for me, var name = "Jonathan"; There, we have a variable holding my name as a string.
Evgeniia Mas
4,452 PointsEvgeniia Mas
4,452 PointsJonathan is right about inserting js in HTML without tags. Agree with him.