Code Monkey home page Code Monkey logo

deli-counter's Introduction

Deli Counter - Take a Number

Objectives

  1. Practice building methods that use iteration and controlling their return values.
  2. Practice manipulating arrays (adding elements, removing elements, etc.).

Instructions

The local deli is putting in a new computerized queue to keep track of their customers and improve productivity. At the beginning of the day, the deli is empty so the queue should be represented by an empty array:

katz_deli = []

Write all of your code in deli_counter.rb

  1. Build the line method that shows everyone their current place in the line. If there is nobody in line, it should say "The line is currently empty.".

  2. Build a method that a new customer will use when entering the deli. The take_a_number method should accept two arguments, the array for the current line of people (katz_deli), and a string containing the name of the person joining the end of the line. The method should call out (puts) the person's name along with their position in line. Top-Tip: Remember that people like to count from 1, not from 0 ("zero") like computers.

  3. Build the now_serving method which should call out (i.e. puts) the next person in line and then remove them from the front. If there is nobody in line, it should call out (puts) that "There is nobody waiting to be served!".

Example usage:

katz_deli = []

take_a_number(katz_deli, "Ada") #=> Welcome, Ada. You are number 1 in line.
take_a_number(katz_deli, "Grace") #=> Welcome, Grace. You are number 2 in line.
take_a_number(katz_deli, "Kent") #=> Welcome, Kent. You are number 3 in line.

line(katz_deli) #=> "The line is currently: 1. Ada 2. Grace 3. Kent"

now_serving(katz_deli) #=> "Currently serving Ada."

line(katz_deli) #=> "The line is currently: 1. Grace 2. Kent"

take_a_number(katz_deli, "Matz") #=> Welcome, Matz. You are number 3 in line.

line(katz_deli) #=> "The line is currently: 1. Grace 2. Kent 3. Matz"

now_serving(katz_deli) #=> "Currently serving Grace."

line(katz_deli) #=> "The line is currently: 1. Kent 2. Matz"

Hint: Review adding and removing elements from an array as well as iterating with index numbers. Also, many of the methods to add and remove elements from an array can also be used to add and remove elements to a string. This will help you solve the lab.

deli-counter's People

Contributors

ahimmelstoss avatar annjohn avatar aviflombaum avatar curiositypaths avatar deniznida avatar drakeltheryuujin avatar dunxtand avatar fislabstest avatar fs-lms-test-bot avatar ihollander avatar ipc103 avatar joll59 avatar kthffmn avatar loganhasson avatar markedwardmurray avatar matbalez avatar maxwellbenton avatar onyoo avatar pletcher avatar ruchiramani avatar sarogers avatar sophiedebenedetto avatar

Watchers

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

deli-counter's Issues

Instructions say return, test says puts

The Instructions say return a persons name and position, but the test doesnt' work unless it is printed or put out. Just a little confusion in the syntax of the instruction

Deli Counter: there are people in line , should display the current line , works with different people in line

def line(katz_deli)
in_line = []
if katz_deli.length == 0
puts "The line is currently empty." // passes the first test
else katz_deli.each do |i|
in_line.push("i + 1. #{katz_deli[i]}")
end
puts "The line is currently: #{in_line}."
end
end

Error message Failures:

  1. Deli Counter #line there are people in line should display the current line
    Failure/Error: line(other_deli)
    TypeError:
    no implicit conversion of String into Integer

    ./deli_counter.rb:6:in `[]'

Trying to figure out how to get everything to print out in one line. Tried to push all items in katz-deli to a new array by using array.each do method. Any ideas/critiques would be appreciated!

Action Items

  • Instance Variables need to be explained
  • Example code led them down rabbit whole of using local variables

The instructions for #take_a_number are incomplete.

Hello! The instructions for #take_a_number currently say that the method should accept two arguments: the array for the current line of people and the string with the name of the person who wants to join the line. They also mention that #take_a_number should "puts" the person's name and their position in line.

This is good, but the instructions ALSO need to mention that #take_a_number should add the person to the end of the line. Otherwise, the program won't work as intended, and the tests won't pass.

Thanks for looking into this!
Sdcrouse

update readme

remove front matter, add objectives, remove booxr link

#line failed

My method failed, but I think it's correct as is:

def line(katz_deli)
if katz_deli.length == 0
puts "The line is currently empty."
else
print "The line is currently: "
katz_deli.each_with_index do |name, index|
print "#{index+1}. #{name} "
end
puts
end
end

Remove Solution Branch

Considering that we deploy this to potential applicants, I think we should remove the solution branch from this lab.

Feedback <<

Would be nice to know you can use << on strings!

Submitted a suggested edit for the Deli Counter Lab instructions

I just submitted a suggested edit to the Deli Counter Lab instructions (in the "README.md" file). This is my first time to submit a suggested change to text in a lesson, so I wanted to be sure I've followed appropriate procedures: I simply clicked the "Edit Lesson' button at the top of the page, made the changes, and clicked submit. I presume this may have resulted in a pull request being automatically issued in the background?

My edit was basically to add missing instructions regarding what should be returned by the #take_a_number method and the #now_serving method.

Thanks!!

Pull Request Issue

After passing the lab I tried to submit pull request, but it didn't work. I tried refreshing my page, and even closed the IDE completely and tried submitting pull request again, but nothing.

difference in task example and spec expectation

Hi! The example provided in the task itself says method "take_a_number" should return the following:
take_a_number(katz_deli, "Matz") #=> 3
However, spec expects the following: "expect($stdout).to receive(:puts).with("Welcome, Ada. You are number 1 in line.")"
Probably, the task's example should be corrected.

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.