Episode 6 - Variables

Exercises

  1. Predict what happens when you run the following code:
    a = 1
    b = 2
    c = a + b
    d = c + a + b
    puts d
  2. Run the following code - you should see an error message. Fix the bug.
    hello = "goodnight"
    world = " moon"
    puts hello + world
    hello = cat
    world = "fish"
    puts hello + world
    x = 1
    y = 2
    puts x + y
  3. What does the following code do:
    a = 1
    b = a
    puts b
  4. What does the following code do:
    a = 1
    b = a
    a = 2
    puts b
    Why do you think that is?