
JavaScript Control Structures
Presentation
•
Computers
•
9th Grade
•
Practice Problem
•
Medium
DeLaina Pruitt
Used 12+ times
FREE Resource
1 Slide • 14 Questions
1
by DeLaina Pruitt
2
Multiple Choice
What will the following program print when run?
for (var j = 0; j < 2; j++) {
for (var i = 6; i > 4; i--){
println (i);
4
5
4
5
6
5
4
6
5
4
6
5
6
5
0
2
6
4
3
Multiple Choice
The following code continually asks the user for a password until they guess the correct password, then ends. But there is one problem.
var SECRET_PASSWORD = "karel";
function start(){
while(true){
var password = readLine("Enter your password: ");
if(password == SECRET_PASSWORD){
println("You got it!");
}
println("Incorrect password, please try again.");
}
}
Change the true in line 4 to be password != SECRET_PASSWORD so that the program doesn’t loop infinitely
Change the true in line 4 to be password == SECRET_PASSWORD so that the program doesn’t loop infinitely
Add a break; statement after line 7 so that the program doesn’t loop infinitely
Put line 9 inside of an else statement
4
Multiple Choice
What is the value of the boolean variable canVote at the end of the program?
var age = 17;
var isCitizen = true;
var canVote = age >= 18 && isCitizen;
True
False
Yes
none, there is a syntax error in this code
5
Multiple Choice
What will be the output of this program?
var number = 5;
var greater_than_zero = number > 0;
if (greater_than_zero){
println(number);
}
0
5
True
Nothing with print
6
Multiple Choice
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);
}
}
0
5
True
Nothing will print
7
Multiple Choice
What is printed by the following program?
var isRaining = false;
var isCloudy = false;
var isSunny = !isRaining && !isCloudy;
var isSummer = false;
var isWarm = isSunny || isSummer;
println("Is it warm: " + isWarm);
Is it warm: true
Is it warm: false
Is it warm: yes
Is it warm: no
8
Multiple Choice
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");
Hello, we are open! Sincerely, the grocery store
Sorry, we are closed!
Sincerely, the grocery store
Hello, we are open!
Sorry, we are closed!
Sincerely, the grocery store
9
Multiple Choice
What will the following program print when run?
var above16 = true;
var hasPermit = true;
var passedTest = false;
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.");
}
}
Issue Driver’s License
Almost eligible for Driver’s License
No requirements met.
Nothing will print
10
Multiple Choice
We want to print the phrase “CodeHS is the best” exactly 25 times. What kind of control structure should we use?
If statement
While loop
Break statement
For loop
11
Multiple Choice
What is the output of the following program?
var result = 0;
var max = 5;
for(var i = 0; i < max; i++){
result += i;
}
println(result);
15
10
0
12345
12
Multiple Choice
What will the following program print when run?
var numberOne = 5;
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);
}
1
1
3
5
1
4
1
4
5
13
Multiple Choice
What is the last thing printed by the following program?
var start = 30;
var stop = 10;
for(var i = start; i >= stop; i-=5){
if(i % 2 == 0){
println(i * 2);
} else {
println(i);
}
}
10
20
30
60
14
Multiple Choice
We want to simulate constantly flipping a coin until we get 3 heads in a row. What kind of loop should we use?
While loop
For loop
Variable loop
Infinite loop
15
Multiple Choice
How many times will the following program print "hello"?
var i = 0;
while(i < 10){
println("hello");
}
9
11
This code will loop infinitely
10
by DeLaina Pruitt
Show answer
Auto Play
Slide 1 / 15
SLIDE
Similar Resources on Wayground
10 questions
Sistem komputer
Presentation
•
10th Grade
13 questions
MACAM MACAM BROWSER
Presentation
•
9th Grade
12 questions
Programming Languages
Presentation
•
8th - 9th Grade
13 questions
Animating with Pivot Animator
Presentation
•
9th Grade
10 questions
Multi-Step Equations with Variables on Both Sides
Presentation
•
9th Grade
12 questions
Repaso Final :Los Numeros (1-100)
Presentation
•
9th Grade
13 questions
Scatterplot, Correlation Coefficients, & Line of Best Fit
Presentation
•
9th Grade
Popular Resources on Wayground
10 questions
Safety Day 2026 – Student Review
Quiz
•
9th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
12 questions
Map Skills
Quiz
•
3rd Grade
22 questions
Continents and Oceans
Quiz
•
5th Grade
15 questions
Rounding Decimals
Quiz
•
5th Grade