jeudi 23 janvier 2020

random number generator with interactive variable

Could someone help me with this its little messy code , but i want to switch theese two if Min > Max because when is min > than max the code still works and its giving wrong numbers , or any advices how to make it cleaner . Thanks a lot

const inputMin = document.getElementById('min');  
const inputMax = document.getElementById('max');
const done = document.getElementById('value');
const rGen = document.getElementById('rGen');

let min = 1;
let max = 100;

inputMin.addEventListener('input', updateValue);
function updateValue(ef) {
    min = + ef.target.value ;      
}
inputMax.addEventListener('input', updateValue1);

function updateValue1(e) {
    max = + e.target.value;

}
    function randomNumber(min, max) {
            return Math.floor(Math.random() * (max - min + 1) + min);

}

rGen.addEventListener('submit', (e) => {

    done["innerText"] = randomNumber(min, max);

    e.preventDefault()


});

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>generator</title>
<link rel="stylesheet" type="text/css" href="css/style.css">

</head>
    <body>

 <form id="rGen" class="form">
    <h1>Click generate </bold></h1>
    <label
            for="min">od
    </label>
    <input type="number" id="min" placeholder='1'>
    <label for="max">do</label>
    <input type="number" id="max" placeholder="100"  size="10"> <br>
    <button class="butt">GENERATE</button>
    <div id="value">
        7
    </div>
 </form>



 <script src="js/script.js"></script>

``




Aucun commentaire:

Enregistrer un commentaire