// Cafe menu items. Note that the id property of each item must correspond exactly // to the index of the item in the items array. var items = [{id:0,item:'Felafel sandwich',cost:'$4.50',meal:'L'},{id:1,item:'Cheese pizza',cost:'$4.50',meal:'L'}, {id:2,item:'Breakfast Burrito',cost:'$3.50',meal:'B'},{id:3,item:'Hamburger',cost:'$4.00',meal:'L'}, {id:4,item:'Mac and Cheese',cost:'$4.50',meal:'D'},{id:5,item:'Muffin',cost:'$2.50',meal:'B'}, {id:6,item:'Salisbury Steak',cost:'$6.50',meal:'D'},{id:7,item:'Pancakes',cost:'$3.50',meal:'B'}, {id:8,item:'Spaghetti',cost:'$4.50',meal:'D'}]; // Order array - initially empty var order = []; // Event handler for order button function orderItem() { // Each of the order buttons has the index of the associated // object hidden in its data-id attribute. Read that attribute // from the button and use it as an index into the items array. order.push(items[$(this).attr('data-id')]); // The View Order button is initially hidden. As soon // as the user orders an item we will want to make it // visible. $('button#viewOrder').show(); // Blur the button to remove the undesirable focussed appearance $(this).blur(); } // Reloads the menu table function displayItems(items) { var table, newRow, button_td, orderButton; var n, length; // Remove any existing entries from the table $('#menu tr').remove(); // Add new rows for the items in the list length = items.length; for(n = 0;n < length;n++) { newRow = $('').html(''+items[n].item+''+items[n].cost+''); orderButton = $('