-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
151 lines (121 loc) · 3.98 KB
/
index.html
File metadata and controls
151 lines (121 loc) · 3.98 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
input,
select,
button {
display: block;
margin: 15px 0;
}
.lds-ring {
display: inline-block;
position: relative;
width: 80px;
height: 80px;
}
.lds-ring div {
box-sizing: border-box;
display: block;
position: absolute;
width: 64px;
height: 64px;
margin: 8px;
border: 8px solid #000;
border-radius: 50%;
animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
border-color: #000 transparent transparent transparent;
}
.lds-ring div:nth-child(1) {
animation-delay: -0.45s;
}
.lds-ring div:nth-child(2) {
animation-delay: -0.3s;
}
.lds-ring div:nth-child(3) {
animation-delay: -0.15s;
}
@keyframes lds-ring {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.hide {
display: none;
}
</style>
</head>
<body>
<label for="">se va a crear una estructura fionachi</label>
<input id="number" type="number" value="">
<!-- <select id="operator">
<option value="+">Sumar</option>
<option value="-">Restar</option>
<option value="/">Dividir</option>
<option value="*">Multiplicar</option>
</select> -->
<button type="button" onclick="operationWithWorker()">validar con worker</button>
<button type="button" onclick="operationWithoutWorker()">validar sin worker</button>
<div id="result"></div>
<div id="spinner" class="lds-ring hide">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<script>
const worker = new Worker('./worker.js');
const spinner = document.querySelector('#spinner');
const showResult = document.querySelector('#result');
const operationWithWorker = () => {
showResult.innerHTML = '';
toogleSpinner();
let input = document.querySelector('#number');
// let operator = document.querySelector('#operator').value;
let value = parseInt(input.value);
worker.postMessage({
number: value
});
}
const operationWithoutWorker = async () => {
showResult.innerHTML = '';
toogleSpinner();
let input = document.querySelector('#number');
let value = parseInt(input.value);
const result = await fibonacci(value);
showResult.innerHTML = result;
console.log(result);
toogleSpinner();
}
const fibonacci = (number) => {
return new Promise((resolve, reject) => {
let values = [0, 1];
for (let i = 0; i < number; i++) {
const numbers = Object.assign([], values);
const value = numbers.reverse().slice(0, 2).reduce((a, b) => a + b);
values.push(value);
}
resolve(values);
})
}
const toogleSpinner = () => {
if (spinner.classList.contains('hide')) {
spinner.classList.remove('hide');
} else {
spinner.classList.add('hide');
}
}
worker.onmessage = (e) => {
showResult.innerHTML = e.data;
console.log(`resultado es: ${e.data}`);
toogleSpinner();
}
</script>
</body>
</html>