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 Combining Strings

EDDY saqchez
EDDY saqchez
635 Points

dont know how to Create a variable named firstName and put your first name in the variable.

script

script.js
var firstName = prompt ('what is your first name');
Var = message 
message + firstName;
document.write(message);
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>
Christopher Roelle
Christopher Roelle
5,426 Points

So first off var firstName = prompt('What is your first name?'); will display a prompt to the user, and will be returned whatever the value the user types, and will store the returned value in a variable called firstName.

Second the line Var = message is actually supposed to be var message; with a semicolon, and the equals should be after the variable name you are declaring, and var should be lowercased as JavaScript is a Case-sensitive language.

third, the line message + firstName; should be message += firstName; or message = message + firstName; The way it is written currently isnt understood by the interpretter, so the first way I wrote it is shorthand for the second way I wrote it, which takes message and sets it equal to itself concattenated with the string of 'firstName'

That should be all the errors you have, I hope this helps, and if you have any questions, just ask. Cheers!