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) Working With Numbers Storing Numbers in Variables

Calvin Secrest
Calvin Secrest
24,815 Points

Create a variable named age and store your age in the variable.

Im not understanding how is the syntax is wrong with this script

script.js
var name = {
  name: "Calvin";
}
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>

12 Answers

J Bacon
PLUS
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
Jose Soto
23,407 Points

The 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
Oleg Polyakov
30,453 Points

The 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
Tom Nguyen
33,500 Points

What I used to pass:

script.js
var age = 99;
var price = 9.9;
Rachelle Wood
Rachelle Wood
15,362 Points

Are 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.

var age = 20;

i can not figure out this question, i tried everything that you posted but none of it seems to work.

me too

Calvin Secrest
Calvin Secrest
24,815 Points

Try 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 :)

whats the second answer/task

nvm

thank you, i finally got past those tasks.