CodeOrc.com - Learn by example
X
Make an RPG
Vue Implementations

Javascript variables

variables hold values, such as words or numbers.

In the example on the right we set hit_points to 12. Change the value to 15 and hit the run button.

You should see that it now says 15, not 12.

Before the print_me function, subtract 5 from hit points, like so:

hit_points = hit_points - 5;

If it worked, the run section should show 10 because 15 - 5 is 10.

DO IT
Did it work? Try to figure it out. If it still doesn't work just click DO IT and we'll fix the code for you.

Create another variable called damage and set it to 9. Next, in place of the 5, put damage.

If you did it right, the value below should be 6.

DO IT
Did it work? Try to figure it out. If it still doesn't work just click DO IT and we'll fix the code for you.
Change damage to 1 and see what happens.
Change hit_points to 100 and see what happens.
Change the minus sign to a plus, see what happens.

With variables you can do alot of math: addition, substraction, multiplication, division, absolute value, etc.

In the next lesson, we will learn about Javascript functions

Get the Latest Tutorial Updates
<< >>
X