-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (37 loc) 路 1.09 KB
/
Copy pathscript.js
File metadata and controls
48 lines (37 loc) 路 1.09 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
40
41
42
43
44
45
46
47
48
const dateOfBirth = document.querySelector("#date-of-birth");
const luckyNumber = document.querySelector("#lucky-number");
const checkNumberButton = document.querySelector("#check-number");
const outputBox = document.querySelector(".output");
function compareValues(sum,number)
{
if(sum%luckyNumber.value === 0){
outputBox.innerText= "WoW Your Birthday is lucky 馃帀";
if(!number)
outputBox.innerText= "Invalid Input";
}
else {
outputBox.innerText= "Sorry !! Your Birthday is not lucky 馃槬";
if(!number)
outputBox.innerText= "Invalid Input";
}
}
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', function checkBirthDateIsLucky()
{
const dob = dateOfBirth.value;
const sum = calculateSum(dob);
if(sum&&dob){
compareValues(sum, luckyNumber.value)
}
else{
outputBox.innerText="Please enter both the fields 馃槨";
}
});