Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done #2111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Done #2111

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
}