-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
125 lines (74 loc) · 3.48 KB
/
script.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const inputValue = document.querySelector(".input-value")
const currencyFrom = document.querySelector(".currency-from")
const textFor = document.querySelector(".text")
const currencyFor = document.querySelector(".currency-for")
const convertButton = document.querySelector(".convert-button")
const realValue = 1
const dolarValue = 5.4
const euroValue = 6
const dolarToEuro = 0.92
const result = document.querySelector(".result")
function buttonConvert() {
if(currencyFrom.value == "REAL" && currencyFor.value == "REAL"){
const finalResult = inputValue.value * 1
const formatedValue = finalResult.toLocaleString('pt-br', {style:'currency', currency:'BRL'})
result.innerHTML = formatedValue
console.log(formatedValue)
}
if (currencyFrom.value == "DOLAR" && currencyFor.value == "DOLAR") {
const finalResult = inputValue.value *1
const formatedValue = finalResult.toLocaleString('en', {style:'currency', currency:'USD'})
result.innerHTML = formatedValue
console.log(formatedValue)
}
if (currencyFrom.value == "EURO" && currencyFor.value == "EURO") {
const finalResult = inputValue.value * 1
const formatedValue = finalResult.toLocaleString('eu', {style:'currency', currency:'EUR'})
result.innerHTML = formatedValue
console.log(formatedValue)
}
if (currencyFrom.value == "REAL" && currencyFor.value == "DOLAR") {
const finalResult = inputValue.value / dolarValue
const formatedValue = finalResult.toLocaleString('en', {style:'currency', currency:'USD'})
result.innerHTML = formatedValue
console.log(formatedValue)
}
if (currencyFrom.value == "REAL" && currencyFor.value == "EURO") {
const finalResult = inputValue.value / euroValue
const formatedValue = finalResult.toLocaleString('eu', {style:'currency', currency:'EUR'})
result.innerHTML = formatedValue
console.log(formatedValue)
}
if(currencyFrom.value == "DOLAR" && currencyFor.value == "REAL"){
const finalResult = inputValue.value * dolarValue
const formatedValue = finalResult.toLocaleString('pt-br', {style:'currency', currency:'BRL'})
result.innerHTML = formatedValue
console.log(formatedValue)
}
if(currencyFrom.value == "DOLAR" && currencyFor.value == "EURO"){
const finalResult = inputValue.value * dolarToEuro
const formatedValue = finalResult.toLocaleString('eu', {style:'currency', currency:'EUR'})
result.innerHTML = formatedValue
console.log(formatedValue)
}
if(currencyFrom.value == "EURO" && currencyFor.value == "DOLAR"){
const finalResult = inputValue.value / dolarToEuro
const formatedValue = finalResult.toLocaleString('en', {style:'currency', currency:'USD'})
result.innerHTML = formatedValue
console.log(formatedValue)
}
if(currencyFrom.value == "EURO" && currencyFor.value == "REAL"){
const finalResult = inputValue.value * euroValue
const formatedValue = finalResult.toLocaleString('pt-br', {style:'currency', currency:'BRL'})
result.innerHTML = formatedValue
console.log(formatedValue)
}
}
//console.log(currencyFor.options[2].value)
/*
if(currencyFrom.value == "REAL" && currencyFor.value == "EURO"){
inputValue = inputValue.value / euroValue
console.log(inputValue.value)
}
*/
convertButton.addEventListener("click", buttonConvert)