HTML and JAVASCRIPT
Write the function that:
Generates a random number using Math.random, saves it using a variable and writes the
number generated (the value of the variable) into the first textbox. Note: Math.random()
generated a random number that is between 0 and 1.
Rounds the random number that was saved in a variable using Math.round and saves it
using a variable and then writes the result into the second textbox. Note: Since the random
number is between 0 and 1 it will round to either zero or one.
If the value of the variable, that contains the rounded number, is equal to zero replace the
image with the image of the heads side of a coin.
Otherwise, if the value of the variable, that contains the rounded number, is equal to one
replace the image with the image of the tails side of the coin.
Following code can be used for this problem-
<!DOCTYPE html>
<html>
<body>
<p> Random Number between 0 and 1- </p>
<p id="random"></p>
<p> Rounded value- </p>
<p id="round"></p>
<img id="Image" src="image.gif" style="width:100px">
<script>
var a = Math.random();
var b = Math.round(a);
document.getElementById("random").innerHTML = a;
document.getElementById("round").innerHTML = b;
if(b==0){
document.getElementById('Image').src='head.gif';
}
else{
document.getElementById('Image').src='tails.gif';
}
</script>
</body>
</html>
Use real source address for images to get the actual results.
HTML and JAVASCRIPT Write the function that: Generates a random number using Math.random, saves it...