-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (33 loc) · 1.28 KB
/
script.js
File metadata and controls
39 lines (33 loc) · 1.28 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
function calculateLove() {
const name1 = document.getElementById('name1').value.trim();
const name2 = document.getElementById('name2').value.trim();
if (name1 === '' || name2 === '') {
alert("Please enter both names!");
return;
}
const lovePercentage = Math.floor(Math.random() * 101);
const result = document.getElementById('result');
result.style.display = "block";
result.style.animation = "love-animation 1s ease-in-out";
result.innerHTML = `${name1} & ${name2}'s love percentage : ${lovePercentage}%`;
if (lovePercentage < 30) {
result.innerHTML += "<br> Not a great match! Keep looking : ("
}
else if (lovePercentage < 70) {
result.innerHTML += "<br> Still, there's potential! Give it a try!"
}
else {
result.innerHTML += "<br> Great match! Love is in the air : )"
}
result.classList.remove("show");
void result.offsetWidth;
result.classList.add("show");
document.querySelectorAll("input").forEach(input => {
input.value = "";
});
document.querySelectorAll("input").forEach(input => {
input.addEventListener("input", () => {
document.getElementById("result").style.display = "none";
});
});
}