Excercise 1:

FizzBuzz

This is a problem used by lots of employers as a warm up excercise during an interview. Write some code in Ruby that prints numbers 1-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. puts 'yes' if 2 > 1
    puts 'maybe' if 1 < 2
  4. Final tip: figure out the difference between 20 % 6
    and
    20 / 6
Try it yourself online!

Excercise 2:

Fibonacci Numbers

This is a problem has lots variations. The first Fibonacci numbers can start with 0 and 1 or 1 and 1. The next numver always equals the sum of the previous two. 0 1 1 2 3 5 8 etc. Can you write code that prints out the first 100 fibonacci numbers?

The employer is testing that you can effectively use variables and a loop. More than that they're looking to see that you're using a small amount of repeating code to do manual work.

  1. You have to be able to print out messages in the console.
  2. You need variables for the first two values.
  3. You have to iterate using a loop.
  4. You have to figure out how to have the last two values availble for addition.

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. arr = [0,1]
    arr << 1
    puts arr[-1]
  4. Final tip: The array is a list of well, whatever you put into it. How can you use it?
Try it yourself online!