-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
64 lines (47 loc) · 2.31 KB
/
scripts.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
const convertButton = document.querySelector('.convert-button');
const currencySelector = document.querySelector('.currency-selector');
function valueConvert(){
const valueInput = document.querySelector('.currencyInput').value;
const dolarToday = 5.25;
const euroToday = 6.20;
const libraToday = 7.20;
const bitcoinToday = 0.000021;
const currencyValueToConvert = document.querySelector('.currency-value-to-convert')
const currencyValueConverted = document.querySelector('.currency-value-converted')
currencyValueToConvert.innerHTML = new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(valueInput);
if(currencySelector.value === 'dolar'){
currencyValueConverted.innerHTML = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(valueInput/dolarToday);
}
if(currencySelector.value === 'euro'){
currencyValueConverted.innerHTML = new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(valueInput/euroToday);
}
if(currencySelector.value === 'libra'){
currencyValueConverted.innerHTML = new Intl.NumberFormat('en-GB', { style: 'currency', currency: 'GBP' }).format(valueInput/libraToday);
}
if(currencySelector.value === 'bitcoin'){
currencyValueConverted.innerHTML = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'BTC' }).format(valueInput/bitcoinToday);
}
}
function currencySwitched(){
const currencyImg = document.querySelector('.currency-image');
const currencyName = document.getElementById('currency-name-converted')
if (currencySelector.value == 'dolar'){
currencyImg.src = './assets/dolar.png';
currencyName.innerHTML = 'Dólar Americano';
}
if (currencySelector.value == 'euro'){
currencyImg.src = "./assets/euro.png";
currencyName.innerHTML = 'Euro';
}
if (currencySelector.value == 'libra'){
currencyImg.src = "./assets/libra.png";
currencyName.innerHTML = 'Libra Esterlina';
}
if (currencySelector.value == 'bitcoin'){
currencyImg.src = "./assets/bitcoin.png";
currencyName.innerHTML = 'Bitcoin';
}
valueConvert();
}
currencySelector.addEventListener('change', currencySwitched);
convertButton.addEventListener('click', valueConvert);