-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.js
99 lines (98 loc) · 3.07 KB
/
project.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
93
94
95
96
97
98
99
//creat pin
document.getElementById("creatPin").addEventListener("click", function(){
var creatPin = Math.round(1000+Math.random()*9000);
document.getElementById("pin").value = creatPin;
})
//get number
function number(num){
var input = document.getElementById("inputPin");
switch(num){
case 1:
input.value += "1";
break;
case 2:
input.value += "2";
break;
case 3:
input.value += "3";
break;
case 4:
input.value += "4";
break;
case 5:
input.value += "5";
break;
case 6:
input.value += "6";
break;
case 7:
input.value += "7";
break;
case 8:
input.value += "8";
break;
case 9:
input.value += "9";
break;
case 0:
input.value += "0";
break;
}
}
//clearScreen
document.getElementById("clear").addEventListener("click", function(){
document.getElementById("inputPin").value = "";
})
//backspace
document.getElementById("clearSpace").addEventListener("click", function(){
var input = document.getElementById("inputPin");
var x = input.value;
if(x.length > 0){
x = x.substring(0, x.length-1)
input.value = x;
}
})
//pin mather function
document.getElementById("submit").addEventListener("click", function(){
var input = document.getElementById("inputPin").value;
var pin = document.getElementById("pin").value;
if(input == '' || pin == ''){
alert("please enter 4 digit pin or click generate pin");
}
else if(input == pin){
display("rightPinNotify","block")
display("wrongPinNotify","none")
document.getElementById("inputPin").value = "";
document.getElementById("pin").value = "";
}
else if(input != pin){
display("rightPinNotify","none")
display("wrongPinNotify","block")
document.getElementById("inputPin").value = "";
var tryLeft = document.getElementById("tryLeft").innerText;
var num = parseInt(tryLeft);
var tryCount = num - 1;
document.getElementById("tryLeft").innerText = tryCount;
if(tryCount <= -1){
document.getElementById("tryLeft").innerText = 0;
}
else if(tryCount == 0){
document.getElementById("submit").style.display = "none";
var notify = document.getElementById("notify");
notify.style.display = "block";
}
}
})
document.getElementById("creatPin").addEventListener("click", function(){
display("submit","block")
document.getElementById("submit").style.margin = "auto";
document.getElementById("submit").style.marginTop = "20px";
display("notify","none")
document.getElementById("tryLeft").innerText = 3;
display("wrongPinNotify","none")
display("rightPinNotify","none")
document.getElementById("inputPin").value = "";
})
function display(id,property){
document.getElementById(id).style.display = property;
}