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 trialCalvin Secrest
24,815 PointsCreate a variable named age and store your age in the variable.
Im not understanding how is the syntax is wrong with this script
var name = {
name: "Calvin";
}
<!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>
12 Answers
J Bacon
Courses Plus Student 2,669 Points- Create a variable named age:
var age
- Add your age to it:
var age = 69;
Jose Soto
23,407 PointsThe prompt is asking for a variable that will return an integer of your age. The variable you have created is an object. In order to get your age from the object, you would have to use name.age
instead of simply using name
.
Instead of creating an object, just store an integer value into a variable:
var age = 50
Oleg Polyakov
30,453 PointsThe correct way:
var name = 'Calvin';
You're creating an object called name:
var name = {};
And then trying to add a property to it called name:
var name = {
name: 'Calvin'
};
Notice that there should be no semicolon (;) after the property (there is in your case). Anyway you should not be working with objects at that stage. How did you come up with the syntax?
Tom Nguyen
33,501 PointsWhat I used to pass:
var age = 99;
var price = 9.9;
Rachelle Wood
15,362 PointsAre you trying to store a string or a number in your variable named age? It looks like you are storing a string in a variable named name and you don't need the curly braces either.
Francisco Castaneda
Full Stack JavaScript Techdegree Student 513 Pointsvar age = 20;
Amyah Aboytes
2,234 Pointsi can not figure out this question, i tried everything that you posted but none of it seems to work.
Maycey Davis
2,792 Pointsme too
Calvin Secrest
24,815 PointsTry not to overthink like I did when working on this task. They are three basic types of variables: strings, numbers and booleans.
For this task it is simply looking for Number, if you have a number of some kind ( floating number, simple number ) you type the special word "var" than you give your variable a name aka "age" and than you assign a value to it using "=" equals sign.
var age = 20;
String are define by anything inside quotation except numbers :
var name = "Name";
Boolean:
var weight = false;
It's as simple as that! Just remember this, when you assign a number, there is no need of quotes, just type the number, if you type quotes, it's a string and finally, when you want to use booleans, you just type true or false - no quotes no nothing. The curly braces is another thing but it's just too early to explain it now :)
Maycey Davis
2,792 Pointswhats the second answer/task
Maycey Davis
2,792 Pointsnvm
Amyah Aboytes
2,234 Pointsthank you, i finally got past those tasks.