Giter Site home page Giter Site logo

deli-counter-001-prework-web'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.

View Deli Counter - Take a Number on Learn.co and start learning to code for free.

deli-counter-001-prework-web's People

Contributors

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deli-counter-001-prework-web's Issues

Output not matching the Rspec expected output

Hi Team,

When running my code on an online editor I get the expected output, however when I run it on terminal I get an error message. I believe is my code, if it is please excuse for the post. I have the following code:

`require 'thread'

katz_deli = []

def line(array)
  if array.count > 1
   output = "The line is currently:"
   array.each_with_index {|val, index| output << " #{index+1}. #{val}"}
   puts output
   else 
     puts "The line is currently empty."
 end
end

def take_a_number(array, name)
  array.push(name)
  puts "Welcome, #{name}. You are number #{array.size} in line."
  end

def now_serving(array)
  queue = Queue.new
  queue = array
  while name = queue.shift
    puts "Currently serving #{name}."
  end
  puts "There is nobody waiting to be served!"
end

Here is the following Rspec failure:

there are no people in line
      should say that the line is empty
    there are people in line
      should serve the first person in line and remove them from the queue (FAILED - 1)

Failures:

  1) Deli Counter #now_serving there are people in line should serve the first person in line and remove them from the queue
     Failure/Error: now_serving(other_deli)

       #<IO:<STDOUT>> received :puts with unexpected arguments
         expected: ("Currently serving Logan.")
              got: ("Currently serving Avi.")
     # ./deli_counter.rb:24:in `puts'
     # ./deli_counter.rb:24:in `now_serving'
     # ./spec/deli_counter_spec.rb:64:in `block (4 levels) in <top (required)>'

Finished in 0.07283 seconds (files took 0.2873 seconds to load)
7 examples, 1 failure

Failed examples:

rspec ./spec/deli_counter_spec.rb:62 # Deli Counter #now_serving there are people in line should serve the first person in line and remove them from the queue
screen shot 2016-08-02 at 7 02 41 pm
`

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.