learn-co-curriculum / badges-and-schedules Goto Github PK
View Code? Open in Web Editor NEWFlatiron school lab
Home Page: www.flatironschool.com
License: Other
Flatiron school lab
Home Page: www.flatironschool.com
License: Other
this solution uses map and each_with_index. We haven't even really discussed 'each' beyond a brief intro. either we move this lab into the 'deeper dive into enumerables' unit or we add brief intro to higher level iterators that are used to solve it and then just get more into them in next unit (enumberables). I like the second option but then think we should move this to the end of the current unit.
Providing a list of attendees right above an instruction requiring you to use a more general array leads to unnecessary confusion. Yes, the instructions below don't ask for an array of those names, but for new coders it seems natural that you'd use that information because why else would it be provided,
note: I haven't finished the lab yet so maybe it becomes useful but from reading ahead I don't believe it is
Numbering of list resets after 2nd item due to markdown rendering issue in Learn. Suggested quick fix: avoid using numbered list here for now
The first two methods were easy enough to write, but assign_rooms
gave me a lot of difficulty. I ended up asking Amanda for help who pointed me to the each_with_index
method on Enumerator (not on Array). Since, according to her, that was the expected answer and it isn't on the Array class, the instructions should hint about the method's existence. The final printer
method gave me trouble to get the test to pass since each string needed it's own puts
command. After some trial and error running the tests, i figured out that I needed to loop over the returned array and individually puts
each string, rather than puts
the entire array, but I came very close to giving up on this lab.
The #batch_badge_creator and #assign_rooms methods can be passed with:
def batch_badge_creator(names_array)
names_array.each do |name|
name.replace("Hello, my name is #{name}.")
end
end
def assign_rooms(names_array)
room = 1
names_array.each do |name|
name.replace("Hello, #{name}! You'll be assigned to room #{room}!")
room += 1
end
end
However, I think this modifies the original array #names_array so the #printer method receives an incorrect array. This results in the #printer method outputting:
Hello, Hello, my name is Edsger.! You'll be assigned to room 1!
Where Hello, my name is Edsger.
should be just Edsger
. We haven't learned about .replace
yet so maybe it should just be stated not to use it in this lab.
Some feedback on this lab:
This lab was really hard - the solution uses #.map, and #.each_with_index, neither of which I think have been taught, or were mentioned. #.map also seems to be the preferred way to iterate through an array? (http://jeromedalbert.com/ruby-how-to-iterate-the-right-way/) Would be nice to learn this if it's used in the solution.
Also, the instructions of "Write a batch_badge_creator method that takes a list of names as an argument and returns a list of badge messages" is not obvious to me that the method takes in an array as an argument, and returns an array. My method was printing a list of badge messages as strings rather than returning all the messages as an array, and it took me way too long to understand that I needed to put those strings into another array.
Bug Description from user:
I was working on the assign_rooms method of the badges and schedules module and typed the following: def assign_rooms(attendees) room_assignments << attendees.each {|i| "Hello, " + i + "! You'll be assigned to room " + "1" + "!"} end I expected it not to pass the rspec test since the room number was not changing but I did it anyway to make sure the rest of my code was working like it should. To my surprise it passed the rspec test so I tried to figure out why.
It looks like the rspec test is coded as follows: it 'should return a list of welcome messages and room assignments' do expect(assign_rooms(attendees)).to eq(room_assignments) but from what I read online it might be better to code it as: it 'should return a list of welcome messages and room assignments' do expect(assign_rooms(attendees)).to eq?(room_assignments) I guess eq? is a stricter equality matcher than just eq.
I changed the rspec to eq? on my cloned copy and reran the test and it failed as expected so I assume the eq? caught the mistake and failed the test. I could be wrong though since I am still wicked new to this stuff.
describe '#printer' do
# Question 4
# The method `printer` should output first the results of the batch_badge_creator method and then of the assign_rooms method to the screen - this way you can output
# the badges and room assignments one at a time.
# To make this test pass, make sure you are iterating through your badges and room assignments lists.
it 'should puts the list of badges and room_assignments' do
badges_and_room_assignments.each_line do |line|
# $stdout is a Ruby global varibale that represents the current standard output.
# In this case, the standard output is your terminal screen. This test, then,
# is checking to see whether or not your terminal screen receives the correct
# printed output.
expect($stdout).to receive(:puts).with(line.chomp)
end
printer(attendees)
end
My tests failed until I eliminated the "badge" method from my code... though the instructions explicitly state that you need to iterate through badges AND room assignments...
Badges and Schedules Lab - cannot fork the lab. Tried to do it via the "Open" button and Nitrous, tried with the "learn open" command via terminal, tried to manually fork and clone, and tried manually with git as well. The lab opens in Sublime Text, but cannot get the "Fork this Lab" to show as done. Cannot move on from lab without this. Fixes?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.