The program I wrote is about how a sports equipment company monitor the trampoline use; it records the customer NAME, and their STATUS (child or adult) that are currently on the trampoline. There are five functions, so we can add customer, display customer and delete the last customer. I am stuck on the last function where I have to use object constructor to identify and then delete the customer.
PS: I can't use any predefined JavaScript array element-deleting or manipulating methods such as delete(), concat(), join(), pop(), push()
const MAX_CUSTOMERS = 5; //maximum customer on the trampoline is 5
var customerList = new Array();//create new Array
function addCustomer ()
{
if (customerList.length >= MAX_CUSTOMERS)
alert('Sorry, no more than ' + String(MAX_CUSTOMERS) + ' customers are allowed on the trampoline.')
else
{
var newIndex = customerList.length;
customerList[newIndex] = new Object;
customerList[newIndex].name = prompt('What is the customer\'s name?'); //ask user enter their name
customerList[newIndex].status = prompt('Are you a Child or an Adult?'); //ask user enter their status
while (!(customerList[newIndex].status == 'child' || customerList[newIndex].status == 'adult'))
{
customerList[newIndex].status = (prompt('Error Please Enter \'child\' or \'adult\':'));
}
}
}
function displayAllCustomers ()
{
var message = '';
for (var i = 0 ; i < customerList.length ; i++)
{
message += customerList[i].name + ', Status: '
+ String(customerList[i].status) + '. \n';
}
if (message == '')
message = 'There are no customer to display!';
alert(message);
}
function deleteLastCustomer ()
{
if (customerList.length > 0)
{
customerList.length--;
alert('The last customer has been deleted.');
}
else
alert('There are no customer to delete!');
}
function identifyThenDeleteCustomer ()
{
var customerName = prompt('Enter the name of the customer to delete:');
var customerStatus = prompt('Enter \'child\' or \'adult\':');
while (!(customerStatus == 'child' || customerStatus == 'adult'))
customerStatus = prompt('Error - enter \'child\' or \'adult\':');
deleteCustomer(customerName,customerStatus);
}
function deleteCustomer (aName, aStatus)
{
;
}
.splice()to remove an element from an array? Is this homework? If so, please offer the exact instructions so we know what is actually being asked.