Random number generator using JavaScript
This program gives the random numbers from 0 to 9.
Code is given below :
1.HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Random Number Generator</title>
<link rel="stylesheet" type="text/css" href="random.css">
</head>
<body>
<div>
<h1>Random Number Generator</h1>
<button onclick="getRandom()">Click</button>
<p id="result"></p>
</div>
</body>
</html>
2.CSS
body
{
padding: 0;
margin: 0;
}
div
{
top: 50%;
left: 50%;
transform:translate(-50%,-50%);
position: absolute;
text-align: center;
width: 400px;
border: 2px solid #111;
padding: 15px;
}
p
{
font-size: 20px;
color: #E67E22;
}
button
{
border: none;
outline: none;
background:#3498DB;
border-radius:15px;
padding: 3px 45px 3px 45px;
font-size: 20px;
}
button:hover
{
background: #2874A6;
color: #fff;
}
3.JavaScript
let result=document.getElementById("result");
function getRandom()
{
let num=Math.floor(Math.random() * 10);
result.innerHTML="Number is : "+num;
}
OUTPUT
Fig. Before click the button. |
Fig. After click the button. Thank You |
Comments
Post a Comment