Professional Documents
Culture Documents
Midterm 2 Review
Midterm 2 Review
Structures, misc.
Francisco (Best TA)
Control Flow
if else
Write a JavaScript program that reads a value representing a number of watts and
displays a message based on the following criteria:
Example:
sum_function(10, 2) -> 0 + 2 + 4 + … + 10
Set the value of the div element with id = “messageArea” with a greeting
using the value calculated above. (Hint: use string c o n c a t e n a t i o n)
Solution
HTML & JS
Write a Javascript program that reads a number with
prompt and prints a table. The first column of the table should
be numbers from 1 up to (and including) the provided number.
The second column should be the square of each number. Your
program must use the message "Enter Value" to read the value
from the user. You don't need to use meaningful variable names
(although you should); however, you must have good
indentation. You don't need to write any CSS. Assume the CSS
for table borders has already been included in the code.
On the right is a table generated when the user
provides 5 as input. Remember that your program
must work for different values (not just 5).
Solution