-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.js
More file actions
35 lines (28 loc) · 780 Bytes
/
menu.js
File metadata and controls
35 lines (28 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* JavaScript 7th Edition
Chapter 3
Project 03-01
Application to calculate total order cost
Author: Professor Richard Krasso
Date: 11/25/2022
Filename: menu.js
*/
let menuItems = document.getElementsByClassName("menuItem");
for (let i = 0; i < menuItems.length; i++)
{
menuItems[i].addEventListener("click", calcTotal);
}
function calcTotal() {
let orderTotal = 0;
for (let i = 0; i < menuItems.length; i++)
{
if (menuItems[i].checked)
{
orderTotal += Number(menuItems[i].value)
}
}
document.getElementById("billTotal").innerHTML = formatCurrency(orderTotal);
}
// Function to display a numeric value as a text string in the format $##.##
function formatCurrency(value) {
return "$" + value.toFixed(2);
}