Skip to content

Instantly share code, notes, and snippets.

@spencereldred
Created September 27, 2013 22:15
Show Gist options
  • Save spencereldred/6735985 to your computer and use it in GitHub Desktop.
Save spencereldred/6735985 to your computer and use it in GitHub Desktop.
Spencer's Week One - Not Quiz
#
# This is our first week's !quiz Let's find out what we know.
#
# 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:
# Make a method that checks your moto speed when called
def check_speed (mph)
if mph >= 20 && mph <= 55
message ="Wheeee!"
elsif mph > 55
message = "Scaree!! Go Slower!"
else
message = "You are a put-put!! Go faster!"
end
puts message += "You are going #{mph} miles per hour."
end
check_speed(15)
check_speed(45)
check_speed(75)
# Make a method to start your bike! It should print out "vrooom!"
# when it's called
# your code below:
def start_your_bike
puts "vrooom!"
end
start_your_bike
# You're the leader of the pack.
# Create an Array of 3 motorcycle makes!
my_convoy = ["Honda", "Harley", "Yamaha"]
# Loop through your convoy and print out each motorcycle's make
# Your code below:
i = 0
my_convoy.each { |bike| puts bike}
# 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}
fred = {name: "Fred", helmet: "Black", height: "6'2''"}
pam = {name: "Pam", helmet: "White", height: "5'4''"}
oscar = {name: "Oscar", helmet: "Silver", height: "5'10''"}
p "#{fred}, #{pam}, #{oscar}"
my_gang = { rider_fred: fred, rider_pam: pam, rider_oscar: oscar}
puts ""
p "#{my_gang}"
# Loop through your gang and print out each rider's
# name & helmet color using a block. Your code below:
my_gang.each {|k,v| puts "#{v[:name]} has a #{v[:helmet]} helmet"}
# 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:
i = 0
my_gang.each do |k,v|
v[:motorcycle] = my_convoy[i]
i += 1
end
p "#{my_gang}"
# 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
def initialize(name, moto_model)
@name = name
@moto_model = moto_model
end
def say_name
puts "Yo #{@name}!!"
end
end
tommy = Rider.new("Tommy", "Suzuki")
tommy.say_name
# A fellow student is noticing that instances of his new Foo class are missing
# their @bar instance variable
class Foo
attr_reader :bar
def initialize(bar)
@bar = bar
end
end
foo = Foo.new("value of bar")
puts foo.bar # TODO value is missing!
# Fix this code so it prints “hello”
class Bar
def initialize
end
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:
john = Rider.new("John", "Harley")
jane = Rider.new("Jane", "Honda")
joan = Rider.new("Joan", "Suzuki")
new_crew = {rider_john: john, rider_jane: jane, rider_joan: joan}
new_crew.each {|k,v| v.say_name }
@featherart
Copy link

Nice work on the first not-quiz!
I'm super psyched to see what you will do with your next project :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment