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 or a using the JavaScript Math.round function. If the rounded number is a load an image of the head side of a coin if it is a 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 h that says: The Random Number
Insert a textbox using the input element. Give it an idSince we are not using a form we will need the id
Insert an h that says: The Rounded Number
Insert another textbox and again give it an id
Insert another textbox and again give it an idIn 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 and
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 and 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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
