function randomIntFromInterval(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
const rndInt = randomIntFromInterval(0, 10000.00)
console.log(rndInt)
<!DOCTYPE html>
<html>
<head>
<title>run game </title>
</head>
<body style=" color: black; margin:auto">
<!-- table border -->
<div class="borderline">
<div>
<h1>$</h1>
<div class="amount">
<p id="amount_print" style="font-size: 24px; font-weight: bold; color: green;"></p>
</div>
<button class="bail" style="height: 50px; width: 150px; background-color: green" onclick="randomIntFromInterval">OPEN-VAULT</button>
<button class="bail" style="height: 50px; width: 150px">STOP</button>
</div>
</div>
</body>
</html>
JavaScript:function randomIntFromInterval(min, max) { return Math.floor(Math.random() * (max - min + 1) + min) } const rndInt = randomIntFromInterval(0, 10000.00) console.log(rndInt) <!DOCTYPE html> <html> <head> <title>run game </title> </head> <body style=" color: black; margin:auto"> <!-- table border --> <div class="borderline"> <div> <h1>$</h1> <div class="amount"> <p id="amount_print" style="font-size: 24px; font-weight: bold; color: green;"></p> </div> <button class="bail" style="height: 50px; width: 150px; background-color: green" onclick="randomIntFromInterval">OPEN-VAULT</button> <button class="bail" style="height: 50px; width: 150px">STOP</button> </div> </div> </body> </html>
tıkladığım yazı yerine yazıcakNereye yazacak, nasıl yazacak? Aklınızda olanları biraz yazıya dökün.
Google'a rastgele sayı üretici yazdığınızda çıkar zaten hocam. Kodlamayla uğraşmaya gerek yok.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>
<span>Min: </span>
<input style="width:50px" type="text" id="min" />
<br />
<span>Max:</span>
<input style="width:50px" type="text" id="max" />
<br />
<span>Tuş:</span>
<input style="width:50px" id="key" />
<br />
<input type="text" style="width:50px" disabled id="value" />
</div>
</body>
<script>
const inputKey = document.getElementById("key");
const inputVal = document.getElementById("value");
const inputMin = document.getElementById("min");
const inputMax = document.getElementById("max");
const numRegEx = /^\d*$/;
let key;
inputKey.addEventListener("input", (inp) => {
if (inp.target.value.length > 1) {
inp.target.value = inp.target.value.slice(0, -1);
}
inp.target.value = inp.target.value.toLowerCase();
})
inputMin.addEventListener("input", (inp) => {
if (!numRegEx.test(inp.target.value)) {
inp.target.value = inp.target.value.slice(0, -1);
}
})
inputMax.addEventListener("input", (inp) => {
if (!numRegEx.test(inp.target.value)) {
inp.target.value = inp.target.value.slice(0, -1);
}
})
document.addEventListener("keypress", (e) => {
if (!inputMin.value || !inputMax.value) return;
min = Number(inputMin.value);
max = Number(inputMax.value);
if (e.key === inputKey.value) {
inputVal.value = Math.floor(Math.random() * (max - min + 1)) + min;
}
})
</script>
</html>
Bu sitenin çalışmasını sağlamak için gerekli çerezleri ve deneyiminizi iyileştirmek için isteğe bağlı çerezleri kullanıyoruz.