-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
110 lines (93 loc) · 3.92 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//Generate pin section
const randomnumber =document.getElementById('generatePin');
randomnumber.addEventListener('click',function(){
let generateNumber= Math.floor(1000 + Math.random() * 9000);
document.getElementById('randomNumberDisplay').value=generateNumber;
});
//button section
function display(userInput){
if(userInput==='C'){
//clear all char at a time
document.getElementById('userInputDisplay').value="";
notify_section('notMatch','none');
notify_section('match','none');
swal("...Empty!..")
}else if(userInput=='<' || userInput=='>'){
let displayValue=document.getElementById('userInputDisplay');
if(document.getElementById('userInputDisplay').value==""){
swal("Input field is empty!", "...Nothing to remove")
notify_section('notMatch','none');
notify_section('match','none');
}
else if(userInput=='>'){
//clear char one by one from left to right
document.getElementById('userInputDisplay').value=displayValue.value.substring(1,displayValue.value.length)
//str=display.value
//str.substring(1,str.length)
//str.slice(1,str.length)
}
else{
//clear char one by one from right to left
document.getElementById('userInputDisplay').value=displayValue.value.substring(0,displayValue.value.length-1)
//str.substring(0,str.length-1)
//str.slice(0,str.length-1);
}
}
else{
document.getElementById('userInputDisplay').value+=userInput;
}
}
//submit section
const submit=document.getElementById('submit');
submit.addEventListener('click',function(){
let displayValue=document.getElementById('userInputDisplay').value;
let randomNumber=document.getElementById('randomNumberDisplay').value;
if((displayValue=="")||(randomNumber=="")){
swal("Empty!", "..Check Input Field & Random Number Field....")
notify_section('notMatch','none');
notify_section('match','none')
}
else{
if(displayValue==randomNumber){
notify_section('match','block');
notify_section('notMatch','none');
//clear random number field & user input field automatically
input_field_clear('randomNumberDisplay');
input_field_clear('userInputDisplay');
}
else{
let updatevalue=0;
let action_left_value=document.getElementById('action_left_value').innerText;
let convertValue=parseInt(action_left_value);
updatevalue=convertValue-1;
document.getElementById('action-left').style.display='block';
if(convertValue>1){
document.getElementById('action_left_value').innerText=updatevalue;
notify_section('notMatch','block');
notify_section('match','none');
//clear user input field automatically
input_field_clear('userInputDisplay');
}else{
swal("OOps!You have alredy try 3 times");
document.getElementById('action-left').style.display='none';
notify_section('notMatch','none');
notify_section('match','none')
//disabled submit button
document.getElementById("submit").disabled = true;
document.getElementById("submit").style.backgroundColor='#cccccc';
document.getElementById("submit").style.color=' #666666';
//clear random number field & user input field automatically
input_field_clear('randomNumberDisplay');
input_field_clear('userInputDisplay');
}
}
}
})
//notify_section
function notify_section(id,value){
document.getElementById(id).style.display=value;
}
//after submit automatically clear input field
function input_field_clear(id){
document.getElementById(id).value="";
}