AP Science Quiz

¡Supera tus tareas y exámenes ahora con Quizwiz!

What symbol represents the and operator in JavaScript? AND and & &&

&&

The value stored in a variable will always be the most recent value assigned. Consider the following code segment. a ← 1 b ← a a ← 2 What value is stored in variable b? 1 2 a 3

1

What is the proper operator for "not equals" in JavaScript? =! != ~= NOT EQUALS

!=

Which of the following Boolean expressions is equivalent to the expression a AND (b OR c) (a AND b) OR c (a AND b) OR (a AND c) (a AND b) AND (a AND c) (b AND c) OR a

(a AND b) OR (a AND c)

How can we check if a variable num is even? num.isEven() will be true (num % 2 == 0) will be true (num % 2 == 0) will be false (num / 2 == 0) will be true

(num % 2 == 0) will be true

An office building 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. The elevator moves when the 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. (onFloor1 AND callTo2) AND (onFloor2 AND callTo1) (onFloor1 AND callTo2) OR (onFloor2 AND callTo1) (onFloor1 OR callTo2) AND (onFloor2 OR callTo1) (onFloor1 OR callTo2) OR (onFloor2 OR callTo1)

(onFloor1 AND callTo2) OR (onFloor2 AND callTo1)

What symbol do you use to do multiplication in JavaScript? x X * #

*

What symbol do you use to do division in JavaScript? % / // *

/

What will be the value of sum after this code runs? var START = 1; var END = 4; function start(){ var sum = 0; for(var i = START; i <= END; i++){ sum += i; } } JavaScript 10 4 1 40

10

What will the following code segment evaluate to? a ← 10 b ← 5 c ← 2 expression = (a - b) * c DISPLAY(expression) 0 10 -10 -5

10

On the AP exam, the ← operator is used for variable assignment. For example, a ← 10 assigns the value 10 to the variable a. Consider the following code segment. a ← 10 b ← 5 c ← a + b What is stored in variable c? 10 5 15 50

15

In the following code, what will be the last number to print to the screen before the program finishes? for (var i = 0; i < 10; i++) { if (i % 2 == 0) { println(i); } else { println(2 * i); } } JavaScript 10 20 9 18

18

On the AP Exam, the modulus operator is denoted by MOD. The MOD operator has the same precedence as the * and / operators. What will c evaluate to in the following code segment? a ← 17 b ← 5 c ← a MOD b 2 3.4 3 5

2

What will the following code segment evaluate to? a ← 9 b ← 5 c ← 4 expression = a + b * c DISPLAY(expression) 29 56 29.0 56.0

29

How many times will the following code print "hello"? for (var i = 0; i < 8; i += 2) { println("hello"); } JavaScript 0 2 4 8

4

What will the following code print to the screen? println(2 + 2); JavaScript 2 + 2 4 22 Nothing

4

What will the following code segment evaluate to? a ← 10 b ← 5 c ← 2 expression = a / b * c DISPLAY(expression) 1 4 2.5 25

4

How many times will the following code print "hello"? for (var i = 3; i < 8; i++) { println("hello"); } JavaScript 3 5 6 8

5

How many times will the following program print "hello"? for (var i = 0; i < 5; i++) { println("hello"); } JavaScript 4 5 6 i

5

What is the proper way to compare if two values are equal in a boolean expression in JavaScript? = == EQUALS is

==

What is a callback function? A function passed to an event handler that is called every time a certain event happens A function called at the bottom of the start function A function that is never called A function called every 20 milliseconds

A function passed to an event handler that is called every time a certain event happens

Why do we use constant variables? To avoid having "magic numbers" in our code To give values a readable name, so that their purpose is clear To let us easily change the behavior of our program by only having to change a value in one place All of the above

All of the above

Consider the code segment below.If the variables onTime and absent both have the value false, what is displayed as a result of running the code segment? Is anyone there? Better late than never. Hello. Is anyone there? Hello. Better late than never.

Better late than never.

To ask the user of the program for a number, which function should you use? readLine readInt readFloat Both readInt and readFloat are for numbers.

Both readInt and readFloat are for numbers.

On the AP exam, INPUT() is used to accept a value from the user and DISPLAY() is used to display a value. Values that are displayed are NOT started on a new line but do contain a space following the value printed. What is displayed as a result if the user inputs "P" to the program? DISPLAY ("Enter a character. ") symbol ← INPUT () DISPLAY (":") DISPLAY ("c") DISPLAY (symbol) "Enter a character. " P":" "c" P Enter a character. P:cP Enter a character. P: c P "Enter a character. " P":" "c" symbol

Enter a character. P: c P

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

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

A summer camp offers a morning session and an afternoon session. The list morningList contains the names of all children attending the morning session, and the list afternoonList contains the names of all children attending the afternoon session. Only children who attend both sessions eat lunch at the camp. The camp director wants to create lunchList, which will contain the names of children attending both sessions. The following code segment is intended to create lunchList, which is initially empty. It uses the procedure IsFound (list, name), which returns true if name is found in list and returns false otherwise. FOR EACH child IN morningList { <MISSING CODE> } Which of the following could replace <MISSING CODE> so that the code segment works as intended? IF (IsFound (afternoonList, child)) { APPEND (lunchList, child) } IF (IsFound (lunchList, child)) { APPEND (afternoonList, child) } IF (IsFound (morningList, child)) { APPEND (lunchList, child) } IF ((IsFound (morningList, child)) OR (IsFound (afternoonList, child))) { APPEND (lunchList, child) }

IF (IsFound (afternoonList, child)) { APPEND (lunchList, child) }

On the AP exam, INPUT() is used to accept a value from the user and DISPLAY() is used to display a value. Values that are displayed are NOT started on a new line but do contain a space following the value printed. What will display after running the following code? a ← "Welcome!" DISPLAY (a) b ← "‎¡Hola!" DISPLAY (b) a ← b b ← "Bonjour!" DISPLAY (a) DISPLAY (b) Welcome!‎¡Hola!‎¡Hola!Bonjour! Welcome! ‎¡Hola! ‎¡Hola! Bonjour! Welcome!‎¡Hola!Welcome!Bonjour! Welcome! ‎¡Hola! ‎Welcome! Bonjour!

Welcome! ‎¡Hola! ‎¡Hola! Bonjour!

On the AP exam, INPUT() is used to accept a value from the user and DISPLAY() is used to display a value. Values that are displayed are NOT started on a new line but do contain a space following the value printed. Consider the code segment below. DISPLAY ("What is your name?") name ← INPUT () DISPLAY ("Hello") DISPLAY (name) What is displayed as a result if the user inputs "Karel" to the program? What is your name? KarelHelloKarel What is your name? KarelHelloKarel What is your name? KarelHello Karel Hello Karel

What is your name? KarelHello Karel

We've written a function animate that moves a ball across the screen like this: function start(){ //add code here } function animate(e){ ball.move(5, 5); } JavaScript How can we set up animate to be called every time a key on the keyboard is pressed down? function start(){ keyDownMethod(callback=animate); } JavaScript function start(){ keyDownMethod(animate); } JavaScript function start(){ keyDownMethod(animate, e); } JavaScript function start(){ keyDownMethod(animate(e)); }

function start(){ keyDownMethod(animate); } JavaScript

What function do you need to call to get the width of the screen? width() getWidth() screenWidth() getScreenWidth()

getWidth()

What are the coordinates of the top right corner of the screen? 0, 0 0, getWidth() getWidth(), 0 getWidth(), getHeight()

getWidth(), 0

What kind of statement allows us to run a block code only if a certain condition is true? if statement break statement else statement for loop

if statement

What kind of statement allows us to run one block of code if one condition is true, and a separate block of code otherwise? if statement break statement if/else statement for loop Answered

if/else statement

Suppose we've written a function drawCircle that we want to call every time the mouse is clicked. How can we do this? mouseClickMethod(drawCircle(e)); JavaScript if(mouseClickMethod){ drawCircle(); } JavaScript mouseClickMethod(drawCircle); JavaScript mouseClickMethod(drawCircle());

mouseClickMethod(drawCircle);

What is the proper function to call to print to the screen? write println PRINT post

println

What function do you need to call to ask the user of the program to enter text? readLine readln text println

readLine

n the following code, we create a circle and add it to the screen. What is the meaning of the x variable? var x = 20; var circle = new Circle(x); add(circle); JavaScript The color of the circle The diameter of the circle The radius of the circle The position of the circle

the radius of the circle

After the following code runs, what is the value of isWeekend? var isSaturday = true; var isSunday = false; var isWeekend = isSaturday || isSunday; JavaScript true false "isWeekend" "isSaturday || isSunday"

true

Determine whether the following expression would evaluate to true or false. 7 = 6 OR 8 ≥ 4 false true

true

What keyword do you need to use to define a variable in JavaScript? variable var int x

var

Which of the following is a good example of a proper constant variable name? var max_value = 100; var MAX_VALUE = 100; var Max_Value = 100; var maxValue = 100;

var MAX_VALUE = 100;

Which of the following is not a valid value for a boolean? true false yes The above are all valid

yes

What symbol represents the or operator in JavaScript? AND and & &&

||


Conjuntos de estudio relacionados

Chapter 13: Financial Statement Analysis

View Set

Lessión 1 Estructura 1.4 Telling time ¿A qué hora? Listen to the audio and fill in the blanks with the time each class meets. Follow the model.

View Set

Urinary Incontinence NCLEX Questions

View Set

Anatomy and Physiology Chapter 1, 2, and 3 Homework

View Set

The Constitiution, the structure of American government

View Set