Midterm #2 Review Questions, CMSC198N
Midterm #2 Review Questions, CMSC198N
These questions will help you prepare for the midterm. Solutions will not be provided, however,
you are welcome to discuss your solutions with TAs and your instructor during office hours. Do
not use a computer when writing JavaScript programs; write your solution on paper then
verify your solutions with the computer. That is the best way for you to prepare for the exam.
Problem 1
a) realHappy# b) HoT
c) temperature d) To2he
a) if b) do
c) function d) segmentVar
a) true b) false
var t = 1;
while (t == 1) ;
a) true b) false
a) true b) false
6. (2 pts) Which of the following allow us to determine the current date in JavaScript?
a) x = x - 1 b) x = x + 1
c) x = x * 10 d) x = x / 10
8. (2 pts) The body of a do while statement will always be executed at least twice.
a) true b) false
9. (2 pts) The body of a while statement will always be executed at least once.
a) true b) false
a) true b) false
Problem 2
<script type="text/javascript">
var x = 100;
var y = 20;
var name = "Bob";
var p = 1;
var t = false;
if (x > y) {
x = x * 3;
p = p - y;
}
t = !t;
</script>
Problem 3
Write a JavaScript program that reads two values. The program will then compute the average of
the values and print a message based on the average. The values must be read using prompt and
the result must be printed using document.writeln. The following data represents the cutoffs to be
used for the generation of the output message:
Use the message “Enter value” to request values. The output should display one of the above
strings. You don’t need to use meaningful variable names.
Problem 4
Write pseudocode for a program that computes the sum of odd values from 1 up to a maximum
value provided by the user.
Problem 5
Write a JavaScript program that implements the pseudocode you define in Problem 4. Your
program will read the maximum value by using the prompt function and it will display the result
by using document.writeln. You don’t need to use meaningful variable names.
Problem 6
A histogram is a graph where each column represents a particular value. Write a program that
reads four values from the user and then plots those values as a histogram. For example, if the
user enters the values 1, 2, 6, 3 your histogram will be:
*
**
******
***