-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
92 lines (87 loc) · 2.91 KB
/
script.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
84
85
86
87
88
89
90
91
92
// declare all id in variable
var confirmationPinCheck = document.getElementById("confirmationPinCheck");
var confirmationPinSubmit = document.getElementById("confirmationPinSubmit");
var mismatchPin = document.getElementById("mismatchPin");
var matchPin = document.getElementById("matchPin");
var actionLeft = document.getElementById("actionLeft");
var notify = document.getElementById("notify");
// alert remover function
function alertRemove(){
mismatchPin.style.display = "none";
matchPin.style.display = "none";
}
// font size and text color fixer function
function fontAndColorFix(){
confirmationPinCheck.style.color = "white";
confirmationPinCheck.style.fontSize="24px"
}
//scroll function
function pageScroll() {
window.scrollBy(0,30);
scrollDelay = setTimeout('pageScroll()',10);
}
//random pin generator
document.getElementById("pinGenerateBtn").addEventListener("click",function(pGF){
var number = "0172469358";
var randomNumber = "";
for(var i=0; i<4; i++){
randomNumber+=number[Math.floor(Math.random()*10)];
}
document.getElementById("generatePinShow").value = randomNumber;
alertRemove();
fontAndColorFix();
actionLeft.innerText = 3;
confirmationPinCheck.value = "";
confirmationPinSubmit.disabled=false;
confirmationPinSubmit.style.backgroundColor="#495BC3";
confirmationPinSubmit.style.color="white";
}
)
//generate pin checker
confirmationPinSubmit.addEventListener("click",function(){
if(confirmationPinCheck.value.length == 4){
if(confirmationPinCheck.value == generatePinShow.value){
matchPin.style.display = "block";
confirmationPinSubmit.disabled = true;
confirmationPinSubmit.style.backgroundColor="green";
confirmationPinSubmit.style.color="white";
pageScroll();
}
else{
mismatchPin.style.display = "block";
pageScroll();
}
}
else{
confirmationPinCheck.value = "Input 4 digit number";
confirmationPinCheck.style.color = "Red";
confirmationPinCheck.style.fontSize = "16px";
}
var tryLeft = parseInt(actionLeft.innerText)-1;
actionLeft.innerText = tryLeft;
if(tryLeft == 0){
if(confirmationPinCheck.value == generatePinShow.value){
confirmationPinSubmit.disabled=true;
pageScroll();
}
else{
confirmationPinSubmit.disabled=true;
confirmationPinSubmit.style.backgroundColor="grey";
confirmationPinSubmit.style.color="white";
}
}
})
//omitButton function to delete number one by one
var omitBtn = document.getElementById("omitBtn");
omitBtn.addEventListener("click", function(){
confirmationPinCheck.value = confirmationPinCheck.value.slice(0,-1);
alertRemove();
fontAndColorFix();
});
//clearButton function to delete all the number at a time
var clearBtn =document.getElementById("clearBtn");
clearBtn.addEventListener("click",function(){
confirmationPinCheck.value="";
alertRemove();
fontAndColorFix();
})