Skip to content

Instantly share code, notes, and snippets.

@samueldowens
Created September 26, 2013 22:48
Show Gist options
  • Save samueldowens/6721674 to your computer and use it in GitHub Desktop.
Save samueldowens/6721674 to your computer and use it in GitHub Desktop.
Day 4 Homework 1
#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.
#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.
#Modify your method so it can take a list of names as an argument and return a list of badge messages.
#Your conference speakers are: Edsger, Ada, Charles, Alan, Grace, Linus and Matz. How you scored these luminaries #is beyond me, but way to go!
#You just realized that you also need to give each speaker a room assignment. You have rooms 1-7. You'll need to #print this for the speakers, so make sure to return a list of room assignments in the form of: "Hello, _____! #You'll be assigned to room _____!"
#Write a method that assigns each speaker to a room, and make sure that each room only has one speaker. Return a #list of room assignments
#Now you have to tell the printer what to print. Create a method that will output the results of the badge method #and schedule method to the screen so the printer can do his thing.
#Write a method to run the rest of your program and print the results to the screen. No other method should print #to the screen.
names = ["Edsger", "Ada", "Charles", "Alan", "Grace", "Linus", "Matz"]
@badges = []
@rooms = []
room = 0
names.each do |name|
room += 1
@badges << "Hello, my name is #{name}."
@rooms << "Hello #{name}! You'll be assigned to room #{room}."
end
def printer
puts @badges
puts @rooms
end
1.times do printer
end
@aviflombaum
Copy link

You should be passing @badges and @rooms into the printer method through arguments, not through increasing the scope to an instance variable.

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