-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
104 lines (86 loc) · 3.04 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
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
const convertButton = document.querySelector('.convert-button')
const currencySelect = document.querySelector('.currency-select')
function convertValues() {
const inputCurrencyValue = document.querySelector('.input-currency').value
const currencyValueToConvert = document.querySelector(
'.currency-value-to-convert',
) // Valor em Real
const currencyValueConverted = document.querySelector('.currency-value') // Outras moedas
const dolarToday = 5.50
const euroToday = 6
const libraToday = 7
const bitcoinToday = 334446
const ieneToday = 0.038
const pesoargToday = 0.0059
if (currencySelect.value == 'dolar') {
currencyValueConverted.innerHTML = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
}).format(inputCurrencyValue / dolarToday)
}
if (currencySelect.value == 'euro') {
currencyValueConverted.innerHTML = new Intl.NumberFormat('de-DE', {
style: 'currency',
currency: 'EUR',
}).format(inputCurrencyValue / euroToday)
}
if(currencySelect.value == 'libra'){
currencyValueConverted.innerHTML = new Intl.NumberFormat('en-UK', {
style: 'currency',
currency: 'GBP'
}).format(inputCurrencyValue / libraToday)
}
if(currencySelect.value == 'bitcoin'){
currencyValueConverted.innerHTML = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'BTC'
}).format(inputCurrencyValue / bitcoinToday)
}
if(currencySelect.value == 'iene'){
currencyValueConverted.innerHTML = new Intl.NumberFormat('ja-JA', {
style: 'currency',
currency: 'JPY'
}).format(inputCurrencyValue / ieneToday)
}
if (currencySelect.value == 'pesoarg') {
currencyValueConverted.innerHTML = new Intl.NumberFormat('es-AR', {
style: 'currency',
currency: 'ARS',
}).format(inputCurrencyValue / pesoargToday)
}
currencyValueToConvert.innerHTML = new Intl.NumberFormat('pt-BR', {
style: 'currency',
currency: 'BRL',
}).format(inputCurrencyValue)
}
function changeCurrency() {
const currencyName = document.getElementById('currency-name')
const currencyImage = document.querySelector('.currency-img')
if (currencySelect.value == 'dolar') {
currencyName.innerHTML = 'Dólar americano'
currencyImage.src = './assets/usa-flag.png'
}
if (currencySelect.value == 'euro') {
currencyName.innerHTML = 'Euro'
currencyImage.src = './assets/euro-icon.png'
}
if(currencySelect.value == 'libra'){
currencyName.innerHTML = 'Libra'
currencyImage.src = './assets/libra-icon.png'
}
if(currencySelect.value == 'bitcoin'){
currencyName.innerHTML = "Bitcoin"
currencyImage.src = './assets/bitcoin-icon.png'
}
if(currencySelect.value == 'iene'){
currencyName.innerHTML = 'Iene'
currencyImage.src = './assets/iene.png'
}
if(currencySelect.value == 'pesoarg'){
currencyName.innerHTML = 'Peso Argentino'
currencyImage.src = './assets/pesoarg.png'
}
convertValues()
}
currencySelect.addEventListener('change', changeCurrency)
convertButton.addEventListener('click', convertValues)