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 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!