Syntax is Below:
function generateRandomNumber(number){ var n = Math.random(); n = n * number; n = Math.floor(n) + 1; return randomDiv.innerHTML = `Your Random Number is ${n}`; }
<!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">
<link rel="stylesheet" href="../styles.css">
<title>JavaScript: Math.random()</title>
</head>
<body>
<h1 class="lesson-h1">JavaScript: Math.random()</h1>
<button id="random-button">Generate Random Number</button>
<span>Between 1 and</span>
<input type="number" name="number" id="number" value="100">
<div id="random-div"></div>
<p>Syntax is Below:</p>
<pre>
function generateRandomNumber(number){
var n = Math.random();
n = n * number;
n = Math.floor(n) + 1;
return randomDiv.innerHTML = `Your Random Number is ${n}`;
}
</pre>
<script>
const random = document.getElementById('random-button');
const number1 = document.getElementById('number');
const randomDiv = document.getElementById('random-div');
random.addEventListener('click', () => {
generateRandomNumber(number.value);
});
function generateRandomNumber(number){
var n = Math.random();
// console.log(n);
n = n * number;
n = Math.floor(n) + 1;
// console.log(n);
return randomDiv.innerHTML = `<h3>Your Random Number is ${n}</h3>`;
}
</script>
<?php
include('../show_code.php');
show_code('index.php');
?>
</body>
</html>