-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
55 lines (49 loc) · 1.94 KB
/
app.js
File metadata and controls
55 lines (49 loc) · 1.94 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Main application logic for QuickQuote.
*
* @file app.js
*/
document.addEventListener('DOMContentLoaded', () => {
const hourlyRateInput = document.getElementById('hourly-rate');
const overheadLaborRateInput = document.getElementById('overhead-labor-rate');
const hoursInput = document.getElementById('hours');
const totalCostElement = document.getElementById('total-cost');
/**
* Calculates the total cost based on hourly rate and hours.
* @returns {number} The calculated total cost.
*/
function calculateTotal() {
const directRate = parseFloat(hourlyRateInput.value) || 0;
const overheadRate = parseFloat(overheadLaborRateInput.value) || 0;
const hours = parseFloat(hoursInput.value) || 0;
return (directRate + overheadRate) * hours;
}
/**
* Updates the total cost display in the header.
*/
function updateTotalDisplay() {
const total = calculateTotal();
totalCostElement.textContent = total.toLocaleString('en-US', {
style: 'currency',
currency: 'USD',
});
}
// Add event listeners to update the total on any input change.
hourlyRateInput.addEventListener('input', updateTotalDisplay);
overheadLaborRateInput.addEventListener('input', updateTotalDisplay);
hoursInput.addEventListener('input', updateTotalDisplay);
// Initial calculation on page load.
updateTotalDisplay();
// Register the service worker for PWA functionality.
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/service-worker.js')
.then(registration => {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
})
.catch(err => {
console.log('ServiceWorker registration failed: ', err);
});
});
}
});