-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
160 lines (137 loc) · 4.2 KB
/
main.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const BASE_URL = 'http://api.currencylayer.com/';
const API_KEY = '777cfc15a74e10ecb14e3696ab2cf70c';
const button = document.querySelector("#money");
let input = document.querySelector("input");
let answer = input.value;
let drop = document.querySelector('.drop')
let downUnder = document.querySelector(".down-under")
let currencies = ['pound', 'aus-dollar', 'euro', 'MX-Pesos', 'canadian-dollar', 'Jap-Yen', 'Rus-Ruble', 'Bitcoin', 'Chinese-Yuan', 'Swiss-Franc', 'Israeli-NewShekel', 'Indian-Rupee', 'South-Korean-Won',
'Brazilian-Real', 'Argentine-Peso', 'Turkish-lira', 'Icelandic-Krona', 'Swedish-Krona', 'Czech-Koruna', 'S-African-Rand']
///)populates drop down
const populateDrop = async () => {
currencies.forEach(cur => {
let op = new Option()
op.value = cur
op.text = cur
drop.options.add(op)
})
}
populateDrop()
///gets data
const apiCall = async (currency) => {
let response = await axios.get(`${BASE_URL}live?access_key=${API_KEY}¤cies=${answer}`);
console.log(response.data.quotes)
let quotes1 = response.data.quotes
let keys = Object.keys(quotes1)
console.log(keys)
let quote = keys.filter(quote => {
if (currency === 'pound') {
if (quote === 'USDGBP') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'aus-dollar') {
if (quote === 'USDAUD') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'euro') {
if (quote === 'USDEUR') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'MX-Pesos') {
if (quote === 'USDMXN') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'canadian-dollar') {
if (quote === 'USDCAD') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'Jap-Yen') {
if (quote === 'USDJPY') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'Rus-Ruble') {
if (quote === 'USDRUB') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'Bitcoin') {
if (quote === 'USDBTC') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'Chinese-Yuan') {
if (quote === 'USDCNY') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'Swiss-Franc') {
if (quote === 'USDCHF') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'Israeli-NewShekel') {
if (quote === 'USDILS') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'Indian-Rupee') {
if (quote === 'USDINR') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'South-Korean-Won') {
if (quote === 'USDKRW') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'Brazilian-Real') {
if (quote === 'USDBRL') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'Argentine-Peso') {
if (quote === 'USDARS') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'Turkish-lira') {
if (quote === 'USDTRY') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'Icelandic-Krona') {
if (quote === 'USDISK') {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'Swedish-Krona') {
if (quote === "USDSEK") {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'Czech-Koruna') {
if (quote === "USDCZK") {
console.log(quotes1[quote])
return quote
}
} else if (currency === 'S-African-Rand') {
if (quote === 'USDZAR') {
console.log(quotes1[quote])
return quote
}
}
})
console.log(quote);
downUnder.innerHTML = quotes1[quote];
//the two lines above call back the result which is the currency rate to the HTML
}
drop.addEventListener('change', (event) => {
console.log(event.target.value)
apiCall(event.target.value)
})