-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (29 loc) · 999 Bytes
/
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
const dateOfBirth = document.querySelector("#data-of-birth");
const luckyNumber = document.querySelector("#lucky-number");
const checkNumberButton = document.querySelector("#check-number");
const outputBox = document.querySelector("#output-box")
function compareValues(sum, luckyNumber) {
if (sum % luckyNumber == 0){
outputBox.innerText = "Your birthday is lucky!!🤞";
}else{
outputBox.innerText = "Your Birthday is not lucky!😢";
}
}
function checkBirthdayDateIsLucky(){
const dob = dateOfBirth.value;
const sum = calculateSum(dob);
if(dob&&sum)
compareValues(sum, luckyNumber.value);
else
outputBox.innerText = 'Please fill out all required fields.';
}
function calculateSum(dob) {
dob = dob.replaceAll("-", "");
let sum = 0;
for(let index=0;index<dob.length;index++)
{
sum = sum + Number(dob.charAt(index));
}
return sum;
}
checkNumberButton.addEventListener('click',checkBirthdayDateIsLucky)