Docsity

6 Problems in Java Script - Midterm Exam 2 | CMSC 198N, Study notes of Computer Science

Toggle sidebar
bg1
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
pf3

Partial preview of the text

Download 6 Problems in Java Script - Midterm Exam 2 | CMSC 198N and more Study notes Computer Science in PDF only on Docsity!

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#c) temperature bd) To2he ) HoT
  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 - 1c) x = x * 10 b) x = x + 1d) 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.

x = 100; var y = 20; varvar namep = 1;= "Bob"; var t = false; if (x >x y)= x{ * 3; } p^ =^ p^ -^ y; t = !t;

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.