-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (52 loc) · 1.75 KB
/
index.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const dateOfBirth = document.querySelector("#date-of-birth");
const luckyNumber = document.querySelector("#lucky-number");
const checkNumberButton = document.querySelector("#check-number");
const outputBox = document.querySelector("#output-box")
const hintButton = document.querySelector("#hint-button")
function compareValues(sum, luckyNumber) {
// console.log(sum,luckyNumber)
if (sum % luckyNumber === 0) {
outputBox.innerText = "Your birthday is lucky🤓!! Moj krdi🤩||";
hintButton.style.display = "none";
} else {
outputBox.innerText = "Birthday is not lucky,,,🤒🤒!!";
showHint(
"Hint");
}
}
function showmsg() {
{
hintButton.innerText = "The sum of digits of your birthday should be divided by your lucky number ||";
}
}
// checkNumberButton.addEventListener('click',function getValues(){
// console.log(typeof dateOfBirth.value);
function checkBirthDateIsLucky() {
const dob = dateOfBirth.value;
const sum = calculateSum(dob);
if (luckyNumber.value && dob) {
compareValues(sum, luckyNumber.value)
} else {
outputBox.innerText = "Please enter both the fields, don't be advance 😏!!";
hintButton.style.display = "none";
}
}
// function showmsg() {
// }
// function hideshowHint() {
// }
function showHint(mg) {
hintButton.style.display = "block";
hintButton.innerText = mg;
}
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', checkBirthDateIsLucky)
hintButton.addEventListener('click', showmsg)
// "2012-12-01"