File tree 1 file changed +27
-2
lines changed
project-6-weight-converter
1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change 1
1
const inputEl = document . getElementById ( "input" ) ;
2
2
3
+ const errorEl = document . getElementById ( "error" ) ;
4
+
5
+ const resultEl = document . getElementById ( "result" ) ;
6
+
7
+ let errorTime ;
8
+
9
+ let resultTime ;
10
+
3
11
function updateResults ( ) {
4
- console . log ( "Input changed!" ) ;
12
+ // console.log(inputEl.value);
13
+ if ( inputEl . value <= 0 || isNaN ( inputEl . value ) ) {
14
+ errorEl . innerText = "Please, enter a valid number!" ;
15
+
16
+ clearTimeout ( errorTime ) ;
17
+ errorTime = setTimeout ( ( ) => {
18
+ errorEl . innerText = "" ;
19
+ errorEl . value = "" ;
20
+ } , 2000 ) ;
21
+ } else {
22
+ resultEl . innerText = ( + inputEl . value / 2.2 ) . toFixed ( 2 ) ;
23
+
24
+ clearTimeout ( resultTime ) ;
25
+ resultTime = setTimeout ( ( ) => {
26
+ resultEl . innerText = "" ;
27
+ inputEl . value = "" ;
28
+ } , 10000 ) ;
29
+ }
5
30
}
6
31
7
- inputEl . addEventListener ( "input" , updateResults ) ;
32
+ inputEl . addEventListener ( "input" , updateResults ) ;
You can’t perform that action at this time.
0 commit comments