JavaScript Control Structures

0.0(0)
studied byStudied by 1 person
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/40

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

41 Terms

1
New cards

Which of the following is not a valid value for a boolean?

yes

2
New cards

What symbol represents the and operator in JavaScript?

&&

3
New cards

What symbol represents the or operator in JavaScript?

||

4
New cards

After the following code runs, what is the value of isWeekend?

var isSaturday = true;
var isSunday = false;
var isWeekend = isSaturday || isSunday;

true

5
New cards

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

==

6
New cards

What is the proper operator for "not equals" in JavaScript?

!=

7
New cards

How can we check if a variable num is even?

(num % 2 == 0) will be true

8
New cards

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

if statement

9
New cards

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/else statement

10
New cards

How many times will the following program print "hello"?

for (var i = 0; i < 5; i++) {
println("hello");
}

5

11
New cards

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);
}
}

18

12
New cards

How many times will the following code print "hello"?

for (var i = 3; i < 8; i++) {
println("hello");
}

5 **YES AGAIN

13
New cards

How many times will the following code print "hello"?

for (var i = 0; i < 8; i += 2) {
println("hello");
}

4

14
New cards

Why do we use constant variables?

All of the Above

15
New cards

Which of the following is a good example of a proper constant variable name?

var MAX_VALUE = 100;

16
New cards

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;
}
}

10

17
New cards

Which of the following returns a random number between 1 and 10?

Randomizer.nextInt(1, 10)

18
New cards

How many possible values can Randomizer.nextBoolean() return?

2

19
New cards

How many times will this program print "hello"?

var i = 10;
while (i > 0) {
println("hello");
i--;
}

10

20
New cards

How many times will this program print "hello"?

var i = 50;
while (i < 100) {
println("hello");
}

This code will loop infinitely

21
New cards

What statement can we use inside of a loop to end it?

break

22
New cards

What is the term for the value that signals the end of user input?

sentinel

23
New cards

Which of the following is correct loop and a half structure?

while(true){
//code
if(condition){
break;
}
//code
}

24
New cards

4.10.5: Better Password Prompt

var SECRET = "abc123";

function start(){
while (true)
var password = ("What is the password? ");
if (password == "abc123") {
break;
}
}
}

25
New cards

Boolean

true or false value.

26
New cards

Logical Operator

Used to make logical associations between boolean values

27
New cards

OR Operator

Logical operator that ___ two boolean values. Written as ||. a || b will be true if a or b is true.

28
New cards

Not Operator

Logical operator that negates a single boolean value. Written as !. !a will be true if a is false, and false if a is true.

29
New cards

And Operator

Logical operator that ___ two boolean values. Written as &&. a && b will be true if both a and b are true.

30
New cards

Comparison Operator

Used to make comparisons between values.

31
New cards

If Statement

lets you ask a question to the program and only run code if the answer is true.

32
New cards

If-Else

Control structure that lets us run either one section of code or another depending on a test.

33
New cards

Event

an action (such as clicking the mouse or pressing a key on the keyboard) that a program detects and uses as input.

34
New cards

For Loop

lets us repeat code a fixed number of times.

35
New cards

Randomize

To generate or select a random object

36
New cards

Psuedorandom

Not actually random, but appears to be random

37
New cards

While Loop

Lets us repeat code as long as something is true

38
New cards

Infinite Loop

A loop that has no eay of stopping, and will keep looping forever

39
New cards

Sentinel

A constant that has the specific purpose of being the value that breaks out of a loop

40
New cards

Break Statement

Statement that breaks out of the current loop, without executing any more code in the loop

41
New cards

Loop-and-a-half

most often set with a while(true), that has a break statement in the loop body.