Code Monkey home page Code Monkey logo

badges-and-schedules's Introduction

Badges and Schedules

Objectives

  1. Define methods that use iteration and control the return values of those methods.
  2. Define methods that call other methods.

Instructions

In this lab you'll be learning how to iterate through an array and output the results in different ways. Write your code in the conference_badges.rb file and you can run the test suite using the learn test command.

Create a badge_maker method

You're hosting a conference and need to print badges for the speakers. Each badge should read: "Hello, my name is _____." Write a badge_maker method that, when provided a person's name, will create and return this message. E.g.:

badge_maker("Arel")
=> "Hello, my name is Arel."

Create a batch_badge_creator method

Once the list of speakers for your conference has been finalized you'll want to get the badges printed for all of your speakers.

  • Write a batch_badge_creator method that takes an array of names as an argument and returns an array of badge messages.

Create an assign_rooms method

You just realized that you also need to give each speaker a room assignment. Write a method called assign_rooms that takes the list of speakers and assigns each speaker to a room. Make sure that each room only has one speaker.

  • You have rooms 1-7.

  • return a list of room assignments in the form of: "Hello, _____! You'll be assigned to room _____!"

  • Hint: Think about how you will assign a room number to each person. Array items are indexed, meaning that you can access each element by its index number. When you are iterating through an array, you can keep track of the index number of the current iteration using an enumerator method called each_with_index or a closely related method called .with_index.

  • Hint: Remember that the return value of the each (or each_with_index) method is the original array that you are calling it on. What we need to do here is iterate through the array containing the list of speakers, create the room assignment strings for each speaker, and return a new array containing the messages. There is an enumerator method that does just that. Google or use Ruby Docs to find the correct method.

Create a printer method

Now you have to tell the printer what to print. Create a method called printer that will output first the results of the batch_badge_creator method and then of the assign_rooms method to the screen.

  • Hint: Remember that methods can call other methods. If the return value of assign_rooms is an array of room assignments, how can you print out each assignment? You'll need to iterate over your array of room assignments in order to puts out each individual assignment.

badges-and-schedules's People

Contributors

ahimmelstoss avatar annjohn avatar arelenglish avatar aviflombaum avatar bhollan avatar deniznida avatar dunxtand avatar fislabstest avatar fs-lms-test-bot avatar ga-be avatar ihollander avatar interestinall avatar kthffmn avatar lizbur10 avatar loganhasson avatar markedwardmurray avatar matbalez avatar maxwellbenton avatar msuzoagu avatar pletcher avatar sarogers avatar scottcreynolds avatar sophiedebenedetto avatar timothylevi avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

badges-and-schedules's Issues

Numbered list renders incorrectly

Numbering of list resets after 2nd item due to markdown rendering issue in Learn. Suggested quick fix: avoid using numbered list here for now

eq versus eq?

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.

Directions are unclear?

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.

@SophieDeBenedetto

Misleading instructions

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

Tests for #batch_badge_creator and #assign_rooms methods not comprehensive enough

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.

The testing expectations seem unclear

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...

Forking lab does not work

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?

Feedback

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.

advanced stuff

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.