File tree 1 file changed +22
-7
lines changed
project-5-currency-converter
1 file changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,29 @@ const worthSecondEl = document.getElementById("worth-second");
8
8
9
9
const exchangeRateEl = document . getElementById ( "exchange-rate" ) ;
10
10
11
- function updateRate ( ) {
12
- console . log ( "Option changed!" ) ;
11
+ updateRate ( ) ;
12
+
13
+ function updateRate ( ) {
14
+ // console.log("Option changed!");
15
+ // fetch(`https://v6.exchangerate-api.com/v6/5f9d1c87f7250159c9c9b17d/latest/${currencyFirstEl.value}`).then((res) => res.json()).then((data) => console.log(data))
16
+
17
+ fetch (
18
+ `https://v6.exchangerate-api.com/v6/2c3b1321a42ead76f059e5cf/latest/${ currencyFirstEl . value } `
19
+ )
20
+ . then ( ( res ) => res . json ( ) )
21
+ // .then((data) => console.log(data))
22
+ . then ( ( data ) => {
23
+ const rate = data . conversion_rates [ currencySecondEl . value ] ;
24
+ // console.log(rate);
25
+ exchangeRateEl . innerText = `1 ${ currencyFirstEl . value } = ${
26
+ rate + " " + currencySecondEl . value
27
+ } `;
28
+ worthSecondEl . value = ( worthFirstEl . value * rate ) . toFixed ( 2 )
29
+ } ) ;
13
30
}
14
31
15
- currencyFirstEl . addEventListener ( "change" , updateRate )
32
+ currencyFirstEl . addEventListener ( "change" , updateRate ) ;
16
33
17
- currencySecondEl . addEventListener ( "change" , updateRate )
34
+ currencySecondEl . addEventListener ( "change" , updateRate ) ;
18
35
19
- worthFirstEl . addEventListener ( "input" , updateRate )
20
-
21
- // Continuing...
36
+ worthFirstEl . addEventListener ( "input" , updateRate ) ;
You can’t perform that action at this time.
0 commit comments