-
-
Save Colt/6735032 to your computer and use it in GitHub Desktop.
Colt's Quiz. He is sad now.
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
# The ideal range of your motor cycle speed 20 - 55. Over 55 is SCAREE! | |
# Check if your moto_speed is within that range using boolean (&&, ||) | |
# operators and comparison operators (== =< >= !=) | |
# if your moto_speed variable is in the right range print out a good | |
# message, aka "Wheee!" Otherwise print out an appropriate response. | |
# Your code goes below: | |
if moto_speed >=20 && moto_speed <=55 | |
puts "Wheee!" | |
elsif moto_speed < 20 | |
puts "Booooo, you're going too slow!" | |
elsif moto_speed >55 | |
puts "Slow down!" | |
end | |
# Make a method that checks your moto speed when called | |
def check_speed (mph) | |
if mph >=20 && mph <=55 | |
puts "Wheee! You're Good!" | |
elsif mph <20 | |
puts "You're going too slow!" | |
elsif mph > 50 | |
puts "You're going too fast. You're going to die!" | |
end | |
end | |
# Make a method to start your bike! It should print out "vrooom!" | |
# when it's called | |
# your code below: | |
def start_bike() | |
print "vrooom!" | |
end | |
# You're the leader of the pack. | |
# Create an Array of 3 motorcycle makes! | |
my_convoy = ["Harley", "Big Dog", "Suzuki"] | |
# Loop through your convoy and print out each motorcycle's make | |
# Your code below: | |
my_convoy.each do |x| | |
puts x | |
end | |
# You need to keep track of your gang. | |
# Create 3 separate Hashes containing riders' info. like so: | |
# fred = { name, helmet, height } | |
# Then a larger Hash containing all riders | |
# my_gang = {rider hashes} | |
my_gang = {} | |
tom = {"name" => "Tom", "helmet" => "Hot Pink", "height" => "4.1"} | |
sally = {"name" => "Sally", "helmet" => "Deep Purple", "height" => "7'1"} | |
ted = {"name" => "Ted", "helmet" => "Baby Blue", "height" => "6.0"} | |
my_gang = {"rider1" => tom, "rider2" => sally,"rider3" => ted} | |
# Loop through your gang and print out each rider's | |
# name & helmet color using a block. Your code below: | |
my_gang.each do |key, value| | |
value.each do |x,y| | |
puts y #I know this prints out all 3 values, but I dont have time to change it! | |
end | |
end | |
# Now for each rider add their motorcycle to their Hash, | |
# assume they are in the same order as your Array | |
# use a loop. Your code below: | |
# Define an Class to represent each gang member | |
# It should include methods to set their name and motorcyle make | |
# When say_name(name) is called the rider's name is printed out | |
Class Rider | |
attr_accessor :name, :moto_model | |
def initialize(name, moto_model) | |
@name = name | |
@moto_model = moto_model | |
end | |
def say_name(rider) | |
puts @name | |
# or maybe puts rider.name? | |
end | |
end | |
# A fellow student is noticing that instances of his new Foo class are missing | |
# their @bar instance variable | |
class Foo | |
attr_reader :bar | |
def intialize(bar) | |
@bar = bar | |
end | |
end | |
foo = Foo.new('value of bar') | |
foo.bar # TODO value is missing! | |
# Fix this code so it prints “hello” | |
class Bar | |
def say_something | |
puts 'hello' | |
end | |
end | |
bar = Bar.new | |
bar.say_something | |
# Final Challenge: | |
# 1. initialize 3 new instances of class Rider | |
# 2. add these to a new Hash | |
# 3. loop through the riders Hash and call say_name for each rider. | |
# Hint: you will need an attr_accessor in Rider to call it's method | |
# Your code below: | |
rider1 = Rider.new("tom", "make1") | |
rider2 = Rider.new("colt", "make2") | |
rider3 = Rider.new("sue", "make3") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks good, well done!
Seems like you just ran out of time but you are pretty strong on your use of all the things we've done this week.