-1
At the moment my code is like this, but it’s very messy, although I think it’s possible to understand the intention.
The question is: How do I get two numbers typed by the user via form and send to a function that will pick a random value between them in React?
import React from 'react';
import '../styles/pagescss/aleatorio.css';
function Aleatorio() {
function refreshPage() {
window.location.reload(false);
}
function declararVariavel() {
var max = document.getElementById('max').value;
var min = document.getElementById('min').value;
}
function getRandomInt(max, min) {
return Math.floor(Math.random() * (max - min)) + min;
}
const Numeros = () => {
return getRandomInt();
};
return (
<div id="corpo">
<h2 id="titulo">JavaScript Math Random</h2>
<p id="texto">A expressão: <br /> Math.floor(Math.random() * (max - min + 1)) + min <br />retorna um numero inteiro aleatorio</p>
<form id="form">
<label id="label">
<input type="number" id="max" placeholder="Máximo" />
<input type="number" id="min" placeholder="Mínimo" />
</label>
<input onclick="declararVariavel()" type="submit" id="botao" placeholder="Enviar" />
</form>
<div id="botao">
<button onClick={refreshPage}>Gerar Números</button>
</div>
<div id="numeroCorpo">
<div id="number">
<Numeros />
</div>
</div>
</div>
);
}
export default Aleatorio;
I want to take the information typed in the two inputs (min
and max
) and put into function getRandomInt()
Observed the response?
– novic