From 4a89f75e17878a8aae831990b7088e9351cf0b3b Mon Sep 17 00:00:00 2001 From: Adrian Rodriguez Date: Fri, 9 Oct 2020 19:53:26 +0000 Subject: [PATCH] Done. --- index.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/index.js b/index.js index e69de29bb2..acadb191ca 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,46 @@ +function takeANumber(currentLine, newPersonName) { + // Take new customer name in + + // Push new customer to end of array + currentLine.push(newPersonName); + var positionInLine = currentLine.indexOf(newPersonName) + 1; + + var welcomeMessage = "Welcome, " + newPersonName + ". You are number " + positionInLine + " in line."; + + return welcomeMessage; +} + +function nowServing(currentLine) { + // If nobody in line, return "There is nobody waiting to be served!" + if (currentLine.length === 0) { + return "There is nobody waiting to be served!"; + } + + // Remove first person in line + var firstInLine = currentLine.shift(); + // Return first person in line + return "Currently serving " + firstInLine + "."; +} + +function currentLine(currentLine) { + if (currentLine.length === 0) { + return "The line is currently empty."; + } + // Create line message + var fullLineMessage = "The line is currently: "; + + // Populate names from currentLine into line message + for (var i = 0; i < currentLine.length; i++) { + // Making the end message look nice without extra ',' at the end + if (i === currentLine.length - 1) { + var currentName = currentLine[i]; + fullLineMessage += i+1 + ". " + currentName; + } else { + var currentName = currentLine[i]; + fullLineMessage += i+1 + ". " + currentName + ", "; + } + } + + // Return line message + return fullLineMessage; +}