WARM UP!

Useful methods:

  1. puts 'Hello Ruby', will print the message between the quotations marks.
  2. puts 'Hello Ruby' if 4 < 2, will print the message between the quotations marks only in the condition (4 < 2) is true.
  3. This repeat the code 5 times, and execute the code between 'do' and 'end'.
    5.times do |num|
      puts num
    end
  4. What will be printed?
    5.times do |num|
      puts num + 2
    end
Try it yourself online!

Exercise 1:

Age restriction

In this problem you have to decide an age restriction and then print a message telling if your age pass the restriction or not.
  1. You have to be able to print out messages in the console.
  2. You need variables to storage your age and the age restriction.
  3. You have to evaluate both variables
Here are the tools you need to solve this one:
  1. my_var = 5, this is how you storage a value inside a variable, you can have different variables with different names.
  2. puts 'Your variable is bigger than 4' if my_var > 4
Try it yourself online!

Exercise 2:

FizzBuzz

This is a problem used by lots of employers as a warm up exercise during an interview. Write some code in Ruby that prints numbers from 1 to 100, BUT for multiples of three, print 'fizz', for multiples of 5 print 'buzz', and for multiples of both print 'fizzbuzz'.
The employer is testing that you know Ruby syntax.
  1. First you have to be able to print out messages in the console.
  2. You have to write a loop, or as Ruby people say, 'iterate'.
  3. You have to be able to figure out multiples using conditional statements.
Here are the tools you need to solve this one:
  1. puts will print your numbers and strings
  2. 100.times do |num|
      puts num
    end
  3. Final tip: figure out the difference between
    20 % 6
    and
    20 / 6
Try it yourself online!