forked from rocketseat-education/convert-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (37 loc) · 1.1 KB
/
script.js
File metadata and controls
42 lines (37 loc) · 1.1 KB
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
handleForm();
function handleForm() {
const form = document.querySelector("form");
const amount = form.querySelector("#amount");
let selectCurr = form.querySelector("#currency");
const footer = document.querySelector("footer");
let description = footer.querySelector("footer #description");
let result = footer.querySelector("footer #result");
let converted,
currValue = 0;
form.onsubmit = (e) => {
e.preventDefault();
switch (selectCurr.value) {
case "USD":
currValue = 5.56;
converted = amount.value * currValue;
break;
case "EUR":
currValue = 6.45;
converted = amount.value * currValue;
break;
case "GBP":
currValue = 7.74;
converted = amount.value * currValue;
break;
}
converted = converted.toString().replace(".", ",").padEnd(2, "0");
description.innerText = `${
selectCurr.value
} 1 = R$ ${currValue.toLocaleString("pt-br", {
style: "currency",
currency: "BRL",
})}`;
result.innerText = `R$ ${converted}`;
footer.classList.add("show-result");
};
}