-4
Hello, my script has a logical syntactic error. Could anyone help me please.
<html>
<head>
<title>Conversor</title>
</head>
<body>
<input type="number" id="num" value="">
<select id="moe1" onchange="converter()" style="display: inline-block;">
<option value="Euro">€</option>
<option value="Dolar">$</option>
<option value="Real">R$</option>
<option value="Libras">£</option>
</select>
<input type="text" id="res" readonly="true">
<select id="moe2" onchange="converter()" style="display: inline-block;">
<option value="Euro">€</option>
<option value="Dolar">$</option>
<option value="Real">R$</option>
<option value="Libras">£</option>
</select>
<script>
document.getElementById('num').addEventListener('input', function (evt) {
converter();
});
function converter() {
var moe1 = document.getElementById('moe1').value
var moe2 = document.getElementById('moe2').value
var num = document.getElementById('num').value
var res = document.getElementById('res')
if (moe1 == moe2) {
res.value = `${num}`
}
if (moe1 == "Euro") {
if (moe2 == "Dolar") {
var calc = num * 1.13
res.value = calc.toFixed(2)
} else if (moe2 == "Real") {
var calc = num * 6.02
res.value = `${calc.toFixed(2)} `
} else if (moe2 == "Libras") {
var calc = num * 0.90
res.value = `${calc.toFixed(2)} `
}
if (moe1 == "Dolar") {
if (moe2 == "Euro") {
var calc = num * 0.89
res.value = `${calc.toFixed(2)} `
} else if (moe2 == "Real") {
var calc = num * 5.33
res.value = `${calc.toFixed(2)} `
} else if (moe2 == "Libras") {
var calc = num * 0.79
res.value = `${calc.toFixed(2)} `
}
if (moe1 == "Real") {
if (moe2 == "Euro") {
var calc = num * 0.17
res.value = `${calc.toFixed(2)} `
} else if (moe2 == "Dolar") {
var calc = num * 0.19
res.value = `${calc.toFixed(2)} `
} else if (moe2 == "Libras") {
var calc = num * 0.15
res.value = `${calc.toFixed(2)} `
}
if (moe1 == "Libras" && moe2 == "Euro") {
if (moe2 == "Euro") {
var calc = num * 1.12
res.value = `${calc.toFixed(2)} `
} else if (moe2 == "Dolar") {
var calc = num * 1.26
res.value = `${calc.toFixed(2)} `
} else if (moe2 == "Real") {
var calc = num * 6.73
res.value = `${calc.toFixed(2)} `
}
}
</script>
</body>
</html>
Hi João, you are basically asking someone to find out where the error in your code is. This is asking someone to work for you for free. Reduce your code until you find out what causes the error. If a doubt persists after finding out exactly what the bug is, then yes, you ask the question, with a code that exemplifies only doubt. But be sure to ask. Everyone misses. https://pt.meta.stackoverflow.com/questions/5483/manual-de-como-n%C3%83o-ask-questions
– Aurium
When an answer solves your difficulty mark it (the best) as accepted. See https://i.stack.Imgur.com/evLUR.png
– user60252