Loops Write a program, using either a for-loop or a while loop, and the document
ID: 3636810 • Letter: L
Question
LoopsWrite a program, using either a for-loop or a while loop, and the document.write() method, that when a button is clicked on the first page, a function is called that writes a new page to the browser window. The new page should be an html table of Celsius temperatures and their Fahrenheit equivalents. The Celsius temperatures should begin at 0 degrees, and each row in the table should increment by 10 degrees C, up to a maximum Celsius value of 100. The table on the new page should look like the following (more or less, the exact style is not important):
Celsius Temperature
Fahrenheit Temperature
0
32
10
50
20
68
30
86
40
104
50
122
60
140
70
158
80 178
90 194
100 212
The formula that converts Celsius to Fahrenheit : degF = (9/5) degC 32
As a base for getting started, check out the grand finale program (annualInterest3.html): grand finale originally given in the examples of for-loops in the Week 6 lecture notes.. It will give you an idea of how to write the basic html code and produce a table on the new page.
If it were me, I would use a for-loop, with a starting (initial) value of degC=0, and use the increment for the loop to be 10, something along the line of
degC= degC 10.
To get full credit the new page you generate needs to be correct with regard to the html (i.e., all basic tags, generated with document.write() outside of the loop), the table itself and the values in it must be generated by a loop. No fair writing the table and its values without using a loop.
When you are finished, or if you have trouble, copy and paste the source code into the body of an email and send it to me.
Explanation / Answer
Option Explicit Dim C As Integer, I As Integer Dim Num As Long, SumN As Long, MaxN As Long, MinN As Long Private Sub Form_Activate() C = InputBox("How many numbers?", "Numbers") For I = 1 To C Num = InputBox("Enter the " & I & " number:", "Numbers") If I = 1 Then MinN = Num MaxN = Num Else If Num MaxN Then MaxN = Num End If End If SumN = SumN + Num Print Num Next Print "The max number was: " & MaxN Print "The min number was: " & MinN Print "The average of the numbers was: " & SumN / C End SubRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.