Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis In Microsoft Excel

Authors: Alex Holloway

1st Edition

B0CCCPKTTX, 979-8852388452

More Books

Students also viewed these Databases questions

Question

Demonstrate three aspects of assessing group performance?

Answered: 1 week ago