0% found this document useful (0 votes)
52 views

Midterm #2 Review Questions, CMSC198N

This document provides sample review questions to help students prepare for a midterm exam on JavaScript fundamentals. It includes 10 multiple choice questions testing concepts like variable naming, loops, data types, and functions. It also provides 4 problems requiring code snippets or pseudocode on topics like trace tables, conditionals, user input/output, and histograms. Students are advised to write solutions by hand before testing them on a computer.

Uploaded by

Karim Hashem
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Midterm #2 Review Questions, CMSC198N

This document provides sample review questions to help students prepare for a midterm exam on JavaScript fundamentals. It includes 10 multiple choice questions testing concepts like variable naming, loops, data types, and functions. It also provides 4 problems requiring code snippets or pseudocode on topics like trace tables, conditionals, user input/output, and histograms. Students are advised to write solutions by hand before testing them on a computer.

Uploaded by

Karim Hashem
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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

1. (2 pts) Which of the following is considered an invalid variable name in JavaScript?

a) realHappy# b) HoT
c) temperature d) To2he

2. (2 pts) Which of the following is not a reserved word?

a) if b) do
c) function d) segmentVar

3. (2 pts) In JavaScript there is only one approach to specify comments.

a) true b) false

4. (2 pts) The following code represents an infinite loop.

var t = 1;
while (t == 1) ;

a) true b) false

5. (2 pts) JavaScript is another name for the Java Programming language.

a) true b) false

6. (2 pts) Which of the following allow us to determine the current date in JavaScript?

a) new GMTVar() b) new Date()


c) DateAndTime() d) new Time()

7. (2 pts) The expression x++ is equivalent to:

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

10. (2 pts) A call to the prompt function returns a string.

a) true b) false
Problem 2

Write a trace table for the following JavaScript program.

<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:

Average >= 90.0  “You did very well”


Average >= 80.0  “You did good”
Less than 80.0  “Not satisfactory”

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:

*
**
******
***

You might also like