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

Ronald Greer
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ronald Greer
Front End Web Development Techdegree Graduate 56,280 Points

I am in big pickle

i really do not understand whats going on here. can someone please send an example?

script.js
var firstName;
firstName = "Kylo";
var lastName;
lastName = "Ren";
var fullName = "message";
message += "Kylo Ren";
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>
Manuel Bichler
Manuel Bichler
Courses Plus Student 876 Points

When the browser starts it will go threw the index.html file. It sees that you have linked to a <script src="script.js"></script>file and he will check that too.

In the script.js file you have defined 3 variables which the browser keeps in mind. He kind of stores them. If you open your developer console in the browser (right click and inspect) you can check the variables. But first you need to tell the browser that you also want to see it in the console. You do that with console.log(variable);

So if you add at the bottom of your script.js the line

console.log(firstName);
console.log(secondName);
console.log(fullName);

you will actually see what the browser has stored in the variables.... hope it helps.

2 Answers

victor cooper
victor cooper
6,408 Points

first line you declare a variable, second line you assign a value to it. third and fourth line do the same. fifth line you declare a variable and assign a value to it. last line will give you an error because you are trying to concatenate an undefined variable with a string.