
JavaScript Control Structures
Presentation
•
Computers
•
9th Grade
•
Practice Problem
•
Medium
DeLaina Pruitt
Used 12+ times
FREE Resource
1 Slide • 14 Questions
1
JavaScript Control Structures
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
JavaScript Control Structures
by DeLaina Pruitt
Show answer
Auto Play
Slide 1 / 15
SLIDE
Similar Resources on Wayground
11 questions
Isotopes
Presentation
•
8th - 9th Grade
11 questions
Discriminant b^2 - 4(a)(c)
Presentation
•
9th Grade
10 questions
Macromolecules
Presentation
•
9th Grade
10 questions
Solving a System of Equations using Substitution
Presentation
•
9th Grade
11 questions
Biodiversity and Human Impacts
Presentation
•
9th Grade
10 questions
Belum Berjudul
Presentation
•
9th Grade
11 questions
8.NS.1, 8.NS.2 Rational/Irrational Numbers
Presentation
•
8th - 9th Grade
11 questions
Classifying Rational Numbers
Presentation
•
8th - 9th Grade
Popular Resources on Wayground
20 questions
STAAR Review Quiz #3
Quiz
•
8th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
6 questions
Marshmallow Farm Quiz
Quiz
•
2nd - 5th Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
20 questions
Inferences
Quiz
•
4th Grade
19 questions
Classifying Quadrilaterals
Quiz
•
3rd Grade
12 questions
What makes Nebraska's government unique?
Quiz
•
4th - 5th Grade
Discover more resources for Computers
7 questions
Warm Up 04.01.2026
Quiz
•
9th Grade
20 questions
Graphing Inequalities on a Number Line
Quiz
•
6th - 9th Grade
20 questions
Linear Functions Review
Quiz
•
9th Grade
30 questions
English 1 STAAR Review
Quiz
•
9th Grade
10 questions
Pythagorean Theorem and its Converse
Quiz
•
7th - 9th Grade
14 questions
Ecological Succession: Primary and Secondary
Quiz
•
9th Grade
2 questions
APRIL 2_4F Practice
Quiz
•
9th Grade
20 questions
Grammar
Quiz
•
9th - 12th Grade