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

var age = { age: "20"; }

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

I understand this as I need to create a variable or var and name it age. I tried different things and even tried lookig at what other people are doing on the discussion thing. Nothing is working.

var age = { age: "20"; }

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

2 Answers

Tsenko Aleksiev
Tsenko Aleksiev
3,819 Points

Hi Michael! You are pushing it a bit :) They are three basic types of variables: strings, numbers and booleans Number:

var age = 20;

String:

var name = "Tsenko";

Boolean:

var isDay = false;

Basically, it goes like this: 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 "=". Is 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 :)

Ricky White
Ricky White
8,799 Points

You're overthinking. Try:

var age = 20;

The age can be an integer, so is written as just 20. If you enclose it in quotes it becomes a string. variables are not wrapped in curly braces.