Back to home

Introduction to Variables

We can compare variables with buckets or boxes that can contain data values. Variables are containers that can store data. We can declare a variable and then initialize it by assigning it with a data value.


Instructions

  1. Now that we have learned about variables if you want to read more about it, I suggest you go to your favorite search engine and then search the term JavaScript variables.
  2. Select one of the results and READ more about the different things about variables.
  3. Now that you have practice doing some RESEARCH about what a variable is in Javascript. Let's go and try to solve this challenge.
  4. If your stuck, don't be afraid to ASK questions and get help from the community.

Follow the steps to accomplish this exercise.

  1. Open Firefox.
  2. Press on F12 to open the developer tools.
  3. Go to the console tab inside of the developer tools of Firefox (The developer tools is going to be your bestfriend for bug hunting).
  4. Type in the console the following:
    • function bucketTest( ){
        console.log('bucket1 is ' + bucket1);
        console.log('bucket2 is ' + bucket2);
      }
      bucketTest();
  5. Inside of the function declare a variable name bucket1 and initialize a value for it by assigning a value of 10.
  6. Inside of the function declare a variable name bucket2 and initialize a value for it by assigning a value of 20.
  7. Now you would see the Run button on the upper left corner try to press that to see the results.
  8. Now our goal is to run a function that will switch the values of bucket1 and bucket2.

THINGS YOU ARE NOT ALLOWED TO DO:

Do not Do not Do not

SPOILER ALERT, ALERT, ALERT!!


js_variable_challenge_img--1

js_variable_challenge_img--2