0
I was trying to make a draw site, where it determines the minimum and maximum values and then a draw is made, returning to you a value between one of these numbers. Here is the html:
function sorteio() {
const min = document.getElementById('minimo').value
const max = document.getElementById('maximo').value
const sorte = Math.floor(Math.random() * (max - min + 1)) + min
document.getElementById('resultado').innerHTML = sorte
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sorteador</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<input type="number" id="minimo"><br><br>
<input type="number" id="maximo"><br><br>
<button onclick="sorteio()">Sorteio</button>
<h1 id="resultado"></h1>
<script src="script.js"></script>
</body>
</html>
When I click the button, it is returned numbers that are not within the preset range. I’ve tried everything, but I can’t solve the problem.
The problem is that you are not using numeric values in your expression you assign to
sorte
, but strings (returned by propertyvalue
). To linked response explains how and why it is important to perform conversions to the type expected in Javascript. The curious thing is that it seems to be the same code you are trying to do, so the answer will probably be of great help. :)– Luiz Felipe
CARACA MLK, TMJ VEI, FUCKING BRABO DEMAIS
– Heitor Lopes