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

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,436 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.

can you show me an example please?