Deli Counter - Take a Number

Objectives

  1. Add elements to an array
  2. Return items from an array
  3. Iterate through an array
  4. Pass an array as a function parameter

Instructions

A pretty important deli needs somebody to program the "Take a Number" feature for their counter.

At the beginning of the day, the deli is empty and is represented by an empty array, e.g.,

var katzDeli = [];

  1. Build a function that a new customer will use when entering the deli. The function, takeANumber, should accept the current line of people, katzDeliLine, along with the new person's name as parameters. The function should return their position in line. And don't go being too programmer-y and give them their index. These are normal people. If they are 7th in line, tell them that. Don't get their hopes up by telling them they are number 6 in line.

  2. Build a function nowServing. This function should return the next person in line and then remove them from the line. If there is nobody in line, it should return "There is nobody waiting to be served!"

  3. Build a function currentLine that returns the current line. For example, if katzDeliLine is currently ["Ada", "Grace"], currentLine(katzDeliLine) would return "The line is currently: 1. Ada 2. Grace". If there is nobody in line, it should return "The line is currently empty."

Hint

Example usage:

var katzDeliLine = [];

takeANumber(katzDeliLine, "Ada"); // 1
takeANumber(katzDeliLine, "Grace"); // 2
takeANumber(katzDeliLine, "Kent"); // 3

currentLine(katzDeliLine); // "The line is currently: 1. Ada 2. Grace 3. Kent"

nowServing(katzDeliLine); // "Currently serving Ada."

currentLine(katzDeliLine); // "The line is currently: 1. Grace 2. Kent"

takeANumber(katzDeliLine, "Matz"); // "3"

currentLine(katzDeliLine); // "The line is currently: 1. Grace 2. Kent 3. Matz"

nowServing(katzDeliLine); // "Currently serving Grace."

currentLine(katzDeliLine); // "The line is currently: 1. Kent 2. Matz"

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