Question: Coin Flip problem - Create a webpage that generates a random number using the JavaScript Math.random function and converts the random number to a 0

Coin Flip problem - Create a webpage that generates a random number using the JavaScript Math.random function and converts the random number to a 0 or a 1 using the JavaScript Math.round function. If the rounded number is a 0 load an image of the head side of a coin if it is a 1 load an image that shows the tails side of a coin. We will use textboxes and buttons but not forms. (use getElementById)
Insert an image of yourself and give that image an id.
Insert an h3 that says: The Random Number
Insert a textbox using the input element. Give it an id.(Since we are not using a form we will need the id.)
Insert an h3 that says: The Rounded Number
Insert another textbox and again give it an id.
Insert another textbox and again give it an id.(In this box you will write the word Heads or Tails.)
Insert a button that when clicked calls a function that you will write.
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 and write heads in the third textbox.
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 and write tails in the third textbox.
 Coin Flip problem - Create a webpage that generates a random

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!