-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
45 lines (39 loc) · 1.52 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
document.addEventListener('DOMContentLoaded', () => {
// Greet function
function greet() {
const userName = prompt("Please enter your name:");
if (userName) {
alert(`Hello, ${userName}, Welcome to my portfolio Website!`);
} else {
alert(`Hello, you didn't enter your name!`);
}
}
// Call greet function on page load
greet();
// Form submission handler
const contactForm = document.getElementById('contact-form');
if (contactForm) {
contactForm.addEventListener('submit', (event) => {
event.preventDefault(); // Prevent form from submitting in the traditional way
alert('Thank you for contacting us! Your message has been submitted successfully.');
contactForm.reset(); // Clear the form fields after submission
});
}
// Dark/Light mode toggle
const toggleButton = document.getElementById('toggle-button');
const body = document.body;
if (toggleButton) {
toggleButton.addEventListener('click', () => {
body.classList.toggle('dark-mode');
body.classList.toggle('light-mode');
// Optional: Change button text based on the current mode
toggleButton.textContent = body.classList.contains('dark-mode')
? 'Switch to Light Mode'
: 'Switch to Dark Mode';
});
// Set initial mode
if (!body.classList.contains('dark-mode')) {
body.classList.add('light-mode');
}
}
});