In: Computer Science
Create a HTML file that prompts the user to enter the number of dice (1-5) to play with and display exactly as shown below (example run on Chrome). If the user enters a number less than 1, then set the number to 1. If the user enters a number greater than 5, then set it to 5.
Center align elements and use height:200px for dice images.
rollDice.html:
When user enters a number less than 1
When user enters a number greater than 5
When the user enters a valid number
Continued on the next page ....
When the user clicks on the button ‘Click to Roll’, call a Javascript function ‘roll()’, which selects a die randomly and rolls it (Two random numbers are generated - one for selecting a die, the other to select roll a number from the die). Based on the output, Javascript changes the image of the selected die while displays the message at the bottom as shown below.
You can add a button in HTML that responds to click by calling the function ‘roll()’ as below.
CONSIDERING THE GIVEN PARAMETERS FROM QUESTION WE SHOW FOLLOWING AS:
CREATING A HTML FILE:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Roll</title>
<base target="_blank" />
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<!-- jQuery library -->
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class='content-wrapper'>
<div class='container'>
<section class='content'>
<div class='row'>
<div class='col-md-12'>
<div class='box box-body'>
<div class='body-custom'>
<form name='Roll_form' action='' method=''>
<br>
<div class='form-group'>
<center>
<input type='text' class='form-control' id='txt_number'
name='txt_number' style='width:100px' />
</center>
</div>
<div class='form-group'>
<center>
<input type='button' class='btn btn-default' id='btn' name='btn'
style='' value='Click to roll' onClick='return roll()' />
</center>
</div>
<div id='loader' style='display:hidden'>
<center><img src='' id='img_selected_die'
style='height:200px;' /></center>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<script>
function roll()
{
var number = document.getElementById('txt_number').value;
if(isNaN(number) == true)
{
alert('Please Enter a Number');
document.getElementById('txt_number').value = '';
}
else
{
if(number < 1)
{
number = 1;
}
else if(number > 5)
{
number = 5;
}
document.getElementById('loader').style.display = 'block';
document.getElementById("img_selected_die").src =
"./roll_"+number+".PNG";
}
}
</script>
</body>
</html>
shutterst Franco Volpatoterseck Shutterstshutterst 2. shuttersto
CorrestedFranco Volpato
Explain : Make a folder , Create a index.html page with above code and place these above images in the same folder with roll_1.PNG , roll_2.PNG name respectively .Run the index.html page in google chrome.
PLEASE UPVOTE ITS VERY NECESSARY FOR ME