-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
69 lines (58 loc) · 2.66 KB
/
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
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
// Task 01 - Notification disable
document.querySelector(".wrong-pin").style.display = "none";
document.querySelector(".correct-pin").style.display = "none";
// Task 02 - Generate pin (4 digit pin)
function generatePin () {
const pin = Math.floor(Math.random() * (9000) + 1000)
document.querySelector(".generatedPin").value = pin;
document.querySelector(".generatedPin").style.textAlign = "center";
}
// Task 03 - Showing the input value
function showInput(number) {
const showValue = document.querySelector(".showValue")
showValue.value = showValue.value + number;
showValue.style.textAlign = "center";
}
// Task 04 - (clear all input) using C calculator
function clearInput() {
document.querySelector(".showValue").value = " ";
}
// Task 05 (Remove element one by one) using < calculator
function removeElement () {
const currentValue = document.querySelector(".showValue").value;
const newValue = currentValue.substring(0, currentValue.length - 1);
document.querySelector(".showValue").value = newValue;
}
// Task 06 - (Check pin) if the pin matched or not
function checkPin () {
const generatedPin = document.querySelector(".generatedPin").value;
const newPin = document.querySelector(".showValue").value;
if(generatedPin == newPin) {
document.querySelector(".correct-pin").style.display = "block";
document.querySelector(".wrong-pin").style.display = "none";
document.querySelector(".generate-btn").style.backgroundColor = "green";
document.querySelector(".submit-btn").style.backgroundColor = "green";
document.querySelector(".submit-btn").disabled = true;
document.querySelector(".generate-btn").disabled = true;
}
else{
document.querySelector(".correct-pin").style.display = "none";
document.querySelector(".wrong-pin").style.display = "block";
document.querySelector(".generate-btn").style.backgroundColor = "red";
document.querySelector(".submit-btn").style.backgroundColor = "red";
document.querySelector(".submit-btn").disabled = false;
document.querySelector(".generate-btn").disabled = true;
let tryLeft = document.querySelector("#tryLeft").innerText
let newTryLeft = parseInt(tryLeft)
if(newTryLeft > 0){
newTryLeft = newTryLeft - 1;
}
document.querySelector("#tryLeft").innerText = newTryLeft
document.querySelector(".showValue").value = ""
if(newTryLeft === 0) {
document.querySelector(".submit-btn").disabled = true;
document.querySelector(".submit-btn").style.backgroundColor = "black";
document.querySelector(".submit-btn").innerText = "PIN LOCKED"
}
}
}