Time for action – changing the number 9 to a different number

Since myNumber is a variable, the value it stores can vary. If we change what is stored in it, the answer to the equation will change too. Follow the ensuing steps:

  1. Stop the game and change 9 to 19.
  2. Notice that when you restart the game, the answer will be 30.

What just happened?

You learned that a variable works by simple process of substitution. There's nothing more to it than that.

We didn't get into the details of the wording used to create myNumber, or the types of variables you can create, but that wasn't the intent. This was just to show you how a variable works. It just holds data so you can use that data elsewhere in your script. We'll get into the finer details of variables in Chapter 3, Variables in Detail.

Have a go hero – changing the value of myNumber

In the Inspector panel, try changing the value of myNumber to some other value, even a negative value. Notice the change in answer in the Console.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.218.221