Question: Create a Web page named hail.html that computes and displays hailstone sequences. The user should be able to enter a positive integer in a text

Create a Web page named hail.html that computes and displays hailstone sequences. The user should be able to enter a positive integer in a text box and then click a button. When the button is clicked, the hailstone sequence starting with the input number should appear in a separate text area, one number per line. If the sequence gets to 1 (meaning it is stuck in the 4-2-1 loop), then your code should print the word "STUCK!" in the text area and terminate. Include a variable that records and displays the length of the hailstone sequence (up to the point where 1 is reached). For example, the hailstone sequence starting with 5 would be displayed as:

5

16

8

4

2

1

STUCK!

Hailstone sequence length: 6

[There are many different ways to test whether a number is even or odd. For example, if num/2 is equal to Math.floor(num/2), then num is an even number. Likewise, because the % operator computes the remainder left over after division, the expression (num % 2 == 0), evaluates to true only if num is even.]

Step by Step Solution

3.35 Rating (167 Votes )

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

Document Format (1 attachment)

Word file Icon

1409-C-S-O-S(1084).docx

120 KBs Word File

Students Have Also Explored These Related Operating System Questions!