Created
July 31, 2018 06:24
-
-
Save sheland/2a5cb9de7580adef0664928548545c46 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #Day 6 refactor your original account generator code to utilize arrays with hashes. | |
| #Complete the following refactor steps: | |
| #Utilize a single array variable to store all student information, | |
| #instead of three individual arrays. This array will contain many hashes. | |
| #Utilize a single loop to drive the hash population | |
| #Update the printing functionality to utilize this new hash variable to print out student roster | |
| new_array = [] | |
| #Inputs student's name 5x names | |
| 5.times do |num| | |
| print "Please enter a first and last name:" | |
| name = gets.chomp.upcase | |
| #Generates 5 random numbers | |
| 5.times do | |
| number = rand(111111..999999).to_s | |
| #Generates 5 email address based on user's names | |
| email = "" | |
| first_name = name[0] | |
| first_initial = first_name[0] | |
| last_name = name.split.last | |
| email = email + first_initial + last_name | |
| last_three_digits = number.to_s[-3..-1] | |
| email = email + last_three_digits + "adadevelopersacademy.org" | |
| grouped = {student_names: name, numbers: number, email_address: number } | |
| new_array << grouped | |
| end | |
| #output names, id, and emails | |
| puts "Names:" | |
| 5.times { |num| puts new_array[num][:student_names] } | |
| puts "Student IDs:" | |
| 5.times { |num| puts new_array[num][:numbers]} | |
| puts "Email addresses:" | |
| 5.times { |num| puts new_array[num][:email_address]} | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shruti has highlighted the bugs in your code. Feel free to let me know if you have questions.