-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
78 lines (54 loc) · 1.55 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
70
71
72
73
74
75
76
77
78
import React ,{useState} from 'react';
import './App.css';
let message='Unlocked';
fetch('https://icanhazdadjoke.com/',{
headers:{
'Accept':'application/json'
}
})
.then(res=>res.json())
.then(res=>res&&res.joke)
.then(joke=>message=joke);
function Grandy(isOpen){
return isOpen && <p>{message}</p>
}
function App() {
const password =[2,2,3];
const [digits ,setDigits]=useState([0,0,0]);
const [isUnlocked,setIsUnlocked,isOpen]=useState(false);
let setDigitAtIndex=(digit,idx)=>{
setDigits((currentDigits)=>
[
...currentDigits.slice(0, idx),
digit,
...currentDigits.slice(idx + 1)
]
);
};
let checkPassword=() =>{
for (let i=0;i<password.length;i++){
if(password[i]!==digits[i]){
setIsUnlocked(false);
return;
}
}
setIsUnlocked(true);
}
return (
<section>
<h1>Your In Or Not🔌</h1>
<div style={{display:"flex",flexDirection:'column', textAign:"center"}}></div>
<div style={{display:'flex'}}>
<input type="number" value={digits[0]}
onChange={(event) => setDigitAtIndex(parseInt(event.target.value),0)}/>
<input type="number" value={digits[1]}
onChange={(event)=>setDigitAtIndex(parseInt(event.target.value),1)}/>
<input type="number" value={ digits[2]}
onChange={(event)=>setDigitAtIndex(parseInt(event.target.value),2)}/>
</div>
<button onClick={()=>checkPassword()}>Press Me</button>
<Grandy isOpen={isUnlocked}/>
</section>
);
}
export default App;