-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
54 lines (44 loc) · 1.84 KB
/
app.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
50
51
52
53
54
// countdown.js
// Set the date we're counting down to (for example, a course launch)
var launchDate = new Date("Dec 31, 2024 00:00:00").getTime();
// Update the countdown every 1 second
var countdownInterval = setInterval(function() {
var now = new Date().getTime();
var distance = launchDate - now;
// Time calculations
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result
document.getElementById("days").innerHTML = days;
document.getElementById("hours").innerHTML = hours;
document.getElementById("minutes").innerHTML = minutes;
document.getElementById("seconds").innerHTML = seconds;
// If the countdown is over, display a message
if (distance < 0) {
clearInterval(countdownInterval);
document.getElementById("timer").innerHTML = "EXPIRED";
}
}, 1000);
// newsletter subscription form validation
document.getElementById("subscribe-form").addEventListener("submit", function(event) {
event.preventDefault();
var email = document.getElementById("email").value;
var message = document.getElementById("form-message");
// Basic email validation
if (email && validateEmail(email)) {
message.textContent = "Thank you for subscribing!";
message.style.color = "green";
message.style.fontWeight = "bold";
} else {
message.textContent = "Please enter a valid email address.";
message.style.color = "red";
message.style.fontWeight = "bold";
}
});
// Simple email validation function
function validateEmail(email) {
var regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return regex.test(email);
}