-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_antigo.js
More file actions
28 lines (23 loc) · 936 Bytes
/
Copy pathscript_antigo.js
File metadata and controls
28 lines (23 loc) · 936 Bytes
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
document.getElementById('currency-form').addEventListener('submit', function(event) {
event.preventDefault();
// Obter valores de entrada
const valor = parseFloat(document.getElementById('amount').value);
const daMoeda = document.getElementById('daMoeda').value;
const paraMoeda = document.getElementById('paraMoeda').value;
const exchangeRates = {
USD: {BRL: 5.73, EUR: 0.92 },
EUR: {BRL: 6.20, USD: 1.09 },
BRL: {USD: 0.17, EUR: 0.16 }
};
// Conversão simples (USD > BRL, BRL > EUR, etc)
let valorConvertido;
if(daMoeda === paraMoeda){
valorConvertido = valor;
}
else {
valorConvertido = valor * exchangeRates[daMoeda][paraMoeda];
}
// Exibir resultado da conversão
const conversao = document.getElementById('conversao');
conversao.textContent = `Resultado: ${valorConvertido.toFixed(2)} ${paraMoeda}`;
});