Sign In Create Account
Variables

We have learned how to do a few things now: make strings, find the length of strings, find what character is in the nth position, do basic math. Not bad for a day's work!

To do more complex coding, we need a way to 'save' the values from our coding. We do this by defining a variable with a specific, case-sensitive name. Once you create (or declare) a variable as having a particular name, you can then call up that value by typing the variable name.

Code:

var varName = data type;

Example:

a. var myName = "Leng";
b. var myAge = 30;
c. var isOdd = true;

Instructions

Create a variable called myAge and type in your age.

?
Stuck? Get a hint! Hint

Remember to not use quotes, or your age will turn into a string. To declare a variable, you only need to type:

var variableName = /* some value */
Files:
script.js
Back to Editor
Start Here

Each lesson starts here. Read the explanation, then follow the instructions underneath. If you get stuck, you can click on the "Hint" for help.

Next  →
Enter your Code

Type your response to the instructions here, in your code editor.

Next  →
See What it Does

Ready to see if your code does what it should? Click "Save + Submit" to run and check your code!

Click "Save + Submit" to run your code! Your code’s output will pop up on the screen.

Next  →
Submit!

This is the terminal. When you submit your code, it will run your code and display the result here.

I'm ready!

Sign in to Codecademy