Unit 4 Test Javascript Control Structures

Ace your homework & exams now with Quizwiz!

Which of the following best describes the result of running the Mystery procedure? a. The result will always be false for any initial value of number b. The result will be false whenever the initial value of number is odd c. The result will be false whenever the initial value of number is even d. The result will always be true for any initial value of number

a. The result will always be false for any initial value of number

What will be the output when the following code runs? function start(){ var loggedIn = true; println("User logged in?: + !loggedIn); a. User logged in? false b. Has a syntax error c. User logged in?: +loggedIn d. User logged in?: true

a. User logged in? false

What is printed by the following program? var isNight = false; var isClear = true; var isSunlight = !isNight && !isClear; var lightIsOn = false; var isBright = isSunlight || lightIsOn; println("Is it warm: " + isWarm); a. Has a syntax error b. Is it warm: true c. Is it warm: + isWarm d. Is it warm: false

b. Is it warm: true

What is the value of the Boolean variable canVote at the end of this program? var age = 18; var isCitizen = true; var canVote = age >= 18 && isCitizen; a. Null b. None, there is syntax error in this codeterm-19 c. False d. True

d. True

In the following code block, assume that the variables rainy and tooCold are boolean. IF ((NOT rainy) AND (NOT tooCold)) { DISPLAY ("It's a good beach day") } Which of the following are equivalent to the above code block? a. IF(NOT (rainy OR tooCold)) { DISPLAY("It's a good beach day") } b. IF (rainy AND tooCold) { DISPLAY("It's a good beach day") } c. IF ((NOT rainy)OR (NOT tooCold)) { DISPLAY("It's a good beach day") } d. IF ((NOT rainy)AND tooCold) { DISPLAY("It's a good beach day") }

a. IF(NOT (rainy OR tooCold)) { DISPLAY("It's a good beach day") }

Which of the following returns a random number between 1 and 10? a. Randomizer.nextInt(1, 10) b. random(1, 10) c. Randomizer.Int(1, 10) d. nextInt(1, 10)

a. Randomizer.nextInt(1, 10)

The AP Exam uses the following relational (comparison) operators: , ,>, <, 2, and s. As well, AND, OR and NOT are used instead of &&, and I=. A comparison using a relational operator evaluates to a Boolean value. For example, a = b evaluates to true if a and b are equal; otherwise, it evaluates to false.. Which of the following Boolean expressions is equivalent to the expression? (a AND b) OR (a AND c) a. a AND (b OR c) b. (a AND b) OR C c. (a AND b) AND (a AND c) d. (b AND c) OR a

a. a AND (b OR c)

A distribution center has two floors. A computer program is used to control an elevator that travels between the two floors. Physical sensors are used to set the following Boolean variables. Variable Description onFloor1 set to true if the elevator is stopped on floor 1; otherwise set to false onFloor2 set to true if the elevator is stopped on floor 2; otherwise set to false callTol set to true if the elevator is called to floor 1; otherwise set to false callTo2 set to true if the elevator is called to floor 2; otherwise set to false The elevator moves when the elevator door is closed and the elevator is called to the floor that it is not currently on. Which of the following Boolean expressions can be used in a selection statement to cause the elevator to move? a. (onFloor1 OR callTo2) OR (onFloor2 OR callTo1) b. (onFloor1 AND callTo2) OR (onFloor2 AND callTo1) c. (onFloor1 AND caliTo2) AND (on Floor2 AND callTo1) d. (onFloors OR callTo2) AND (onFloor2 OR callTo1)

b. (onFloor1 AND callTo2) OR (onFloor2 AND callTo1)

How many times will the following program print "hello"? var i = 0; while(i < 10){ println("hello"); i++; } a. 9 b. 10 c. 11 d. This code will loop infinitely

b. 10

What will the following program print when run? (Select all the values that will print) var numberOne = 15; var numberTwo = 10; if (numberOne == 5) { println(1); } if (numberOne > 5) { println(2); } if (numberTwo < 5) { println(3); } if (numberOne < numberTwo) { println(4); } if (numberOne != numberTwo) { println(5); } a. 1 b. 2 c. 3 d. 4 e. 5

b. 2 e. 5

What will the following program print when run? var above16 = true; var hasPermit = true; var passedTest = true; if (above16 && hasPermit && passedTest){ println("Issue Driver's License"); } else { if (above16 || hasPermit || passedTest) { println("Almost eligible for Driver's License"); } else { println("No requirements met."); } } a. Nothing will print b. Issue Driver's License c. Almost eligible for Driver's License d. No requirements met.

b. Issue Driver's License

The AP Exam does not use for loops and while loops, but rather REPEAT or REPEAT UNTIL commands as shown below. REPEAT n TIMES { <block of statements> } REPEAT UNTIL(condition) { <block of statements> } Consider the following program, which is intended to print the sum of all the positive integers up to number sum U REPEAT number TIMES { sum-sum number } DISPLAY SUM Which of the following best describes the behavior of this program? a. The program does not work as intended but rather it displays the number squared b. The program does not work as intended because sum should be initialized to 1. c. The program does not work as intended but rather it displays the number factorial. d. The program correctly displays the number factorial

b. The program does not work as intended because sum should be initialized to 1.

We want to have a program ask the user for a password until they enter the secret password . What type of loop should we use? a. Loop and a half b. While loop c. Infinite loop d. For loop

b. While loop

What will be the output of this program? var number = 5; var greater__than__zero = number > 0; if (greater__than__zero){ if (number <= 5){ println(number); } } a. True b. 0 c. 5 d. Nothing will print

c. 5

We want to print the phrase "Mr. Fromm is the best" exactly 50 times. What kind of control structure should we use? a. While loop b. Loop and a half c. For loop d. If statement

c. For loop

Consider the following program. Which of the following is NOT a possible output when this runs? function start(){ var mysteryNum = 10 * Randomizer.nextInt(2,8); println(mysteryNum); } a. 20 b. 50 c. 70 d. 10

d. 10

The AP Exam uses the following relational (comparison) operators: =, , >, <, 2, and s. As well, AND, OR and NOT are used instead of &&, | | and != . A comparison using a relational operator evaluates to a Boolean value. For example, a = b evaluates to true if a and b are equal; otherwise, it evaluates to false. Determine what the following expression would evaluate to. (9 is greater than 7 AND 17 is greater than 4) OR 65 is greater than 9 a. no b. yes c. false d. true

d. true

What will the following program print when run? for (var j = 0; j < 2; j++) { for (var i = 6; i >=4; i--){ println(i); } ) a. 4 5 4 5 b. 6 5 6 5 c. 0 2 6 4 d.6 5 4 6 5 4

d.6 5 4 6 5 4

What will be the output of this program? var number = 0; var greater__than__zero = number > 0; if (greater__than__zero) { println(number); } a.5 b.0 c.True d.Nothing will print

d.Nothing will print

What is printed by the following program? var numApples = 10; var numOranges = 5; if(numApples > 20 || numOranges == numApples){ println("Hello, we are open!"); } else { println("Sorry, we are closed!"); } println("Sincerely, the grocery store"); a. Sincerely,the grocery store b. Hello, we are open! c. Sorry, we are closed! d. Hello, we are open! Sincerely, the grocery store e. Sorry, we are closed! Sincerely, the grocery store

e. Sorry, we are closed! Sincerely, the grocery store


Related study sets

CHEMISTRY (A STORY OF TWO SUBSTANCES)

View Set

AZ-500 Monitoring Security with Azure Monitor

View Set

International Marketing Chapter 13 LearnSmart

View Set

EXSC 428 Exam 01 - Cardiorespiratory Exercise Prescription

View Set

Government Multiple Choice Exam #1

View Set

Chapter 13. Streams and Flooding

View Set