0
I am creating a numerical converter. but due to my knowledge limited, I cannot program it so that every time it reaches a multiple of 200 in the counter, 4 is added in the result.
I even got a result by creating an individual variable for each multiple, but I believe that is not the most appropriate form.
And also my accountant is computing negative values.
<!DOCTYPE html>
<html>
<title>Conversor</title>
<body>
<h2>Conversor</h2>
<p>Conversor:</p>
<p>
<label>valor</label>
<input id="inputValor" type="number" placeholder="valor" oninput="Conversor(this.value)" onchange="Conversor(this.value)">
</p>
<p>Resultado: <span id="outputValor"></span></p>
<script>
function Conversor(valNum) {
var kwh = valNum;
var gre;
if (kwh >= 200) {
gre= 4;
} else {
gre= 2;
}
var b2 = valNum;
var add;
if (b2 >= 200) {
add = 4;
} else {
add = 0;
}
var add2;
if (b2 >= 400) {
add2 = 4;
} else {
add2 = 0;
}
document.getElementById("outputValor").innerHTML=valNum*gre+add+add2;
}
</script>
</body>
</html>
What error appears in?
– Ronaldo Araújo Alves
Good morning Ronaldo. It’s running, only I’d like to know if you have any better method than the one I did, because that way I’ll have to make a variable for each multiple of 200. to add 4 to the result.
– Jonathan Santos