This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FizzBuzz part 1 | |
def fizzbuzz(until_num) | |
i = 1 | |
while i <= until_num do | |
if i % 3 == 0 && i % 5 == 0 | |
puts "FizzBuzz" | |
elsif i % 3 == 0 | |
puts "Fizz" | |
elsif i % 5 == 0 | |
puts "Buzz" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
songs = [ | |
"The Magnetic Fields - 69 Love Songs - Parades Go By", | |
"The Magnetic Fields - Get Lost - Smoke and Mirrors", | |
"Neutral Milk Hotel - In An Aeroplane Over the Sea - Holland 1945", | |
"The Magnetic Fields - Get Lost - You, Me, and the Moon", | |
"The Magnetic Fields - 69 Love Songs - The Book of Love", | |
"Neutral Milk Hotel - In An Aeroplane Over the Sea - The King of Carrot Flowers" | |
] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You're hosting a conference and need to print badges for the speakers. Each badge should say: "Hello, my name is _____." | |
# Write a method that will create and return this message, given a person's name. | |
def badge(name) | |
puts "Hello, my name is #{name}." | |
end | |
# Now the list of speakers is finalized, and you can send the list of badges to the printer. Remember that you'll need to give this list to the printer, so it should be accessible outside of the method. | |
speaker_list = %w(John Mike Liz Harry Betty) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let's go back to the exercise where we determined what is and isn't a vowel. With ruby, there's always more than one way to do something and get the same result. | |
# Assuming vowels a,e,i,o,u: | |
# Write a method that returns whether a given letter is a vowel, using if and elsif | |
def is_vow(letter) | |
if letter == "a" | |
true | |
elsif letter == "e" | |
true | |
elsif letter == "i" | |
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Download this file: | |
# https://gist.github.com/scottcreynolds/ac1b5c8d96de0c91bf7c/download | |
# Run it from your terminal with: | |
# ruby ruby_phone_format.rb | |
# (Just make sure you are in the right directory) | |
# ====================================== | |
# Ignore All This Code | |
# ====================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Download Gist: https://gist.github.com/scottcreynolds/e6534b284373efe0ba6e/download | |
# Build a Jukebox | |
# create a file jukebox.rb | |
# When that program is run, it should introduce itself | |
# to the user and accept input from the user using the gets command. | |
# The jukebox should respond to 4 commands, help, play, list and exit. | |
# The help command should output instructions for the user | |
# on how to use the jukebox. | |
# The list command should output a list of songs that the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Apple picker | |
# Create a method, apple_picker, that will pick all the apples out of an array. Implement it with collect and then implement it with select. Write a sentence about how select differs from collect. | |
def apple_picker(fruits) | |
answer = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You need to program the "Take a Number" feature for a deli. At the start, the deli is empty and is represented by an empty array. | |
# Build a method that a new customer will use when entering our deli. The method, take_a_number, should accept the current line of people, along with the new person's name, and return their position in line (and no 0 index, these are normal people, if they are 7th in line, tell them that, not 6). | |
def take_a_number(place, person) | |
place << person | |
place.length.to_s | |
end | |
# Build a method now_serving. This method should call out (via puts) the next person in line and remove them from the line. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Movie collection by genre | |
movies = { | |
:animation => ["Incredibles", "Little Mermaid", "Cars"] | |
:comedy => ["Zoolander", "Groundhog Day"], | |
:drama => ["Little Women", "JFK", "Black Stallion"] | |
} | |
# Recipes with ingredients |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Holiday suppliers | |
# You have a bunch of decorations for various holidays organized by season. | |
holiday_supplies = { | |
:winter => { | |
:christmas => ["Lights", "Wreath"], | |
:new_years => ["Party Hats"] | |
}, | |
:summer => { | |
:forth_of_july => ["Fireworks", "BBQ"] |
OlderNewer