-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
49 lines (40 loc) · 1.76 KB
/
script.js
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
// Modal functionality
const loginBtn = document.getElementById('loginBtn');
const loginModal = document.getElementById('loginModal');
const closeModal = document.querySelector('.close');
const startAssessmentBtn = document.getElementById('startAssessmentBtn');
loginBtn.addEventListener('click', () => {
loginModal.classList.remove('hidden');
});
closeModal.addEventListener('click', () => {
loginModal.classList.add('hidden');
});
window.addEventListener('click', (event) => {
if (event.target === loginModal) {
loginModal.classList.add('hidden');
}
});
// Calculate Green Living Score
function calculateScore() {
const carUsage = parseInt(document.getElementById('carUsage').value);
const energyUse = parseInt(document.getElementById('energyUse').value);
const wasteManagement = parseInt(document.getElementById('wasteManagement').value);
const ecoPurchases = parseInt(document.getElementById('ecoPurchases').value);
const totalScore = carUsage + energyUse + wasteManagement + ecoPurchases;
document.getElementById('score').innerText = `Score: ${totalScore}`;
// Example suggestions based on score
let suggestions = '';
if (totalScore < 5) {
suggestions = 'Consider adopting more eco-friendly practices.';
} else if (totalScore < 10) {
suggestions = 'You are doing well! Try to improve further.';
} else {
suggestions = 'Excellent! Keep up the great work!';
}
document.getElementById('suggestions').innerText = suggestions;
document.getElementById('results').classList.remove('hidden');
}
// Show the assessment section when the button is clicked
startAssessmentBtn.addEventListener('click', () => {
document.getElementById('assessment').scrollIntoView({ behavior: 'smooth' });
});