
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
Properties of Integer Exponents
Presentation
•
8th - 9th Grade
11 questions
For loops
Presentation
•
8th - 10th Grade
10 questions
2.4 Day 2 Solving Multi-Step Inequalities
Presentation
•
9th Grade
12 questions
Springboard 3.4 MLA format
Presentation
•
9th Grade
10 questions
Website Design
Presentation
•
8th - 9th Grade
12 questions
Density: Area & Volume
Presentation
•
9th Grade
13 questions
1.4 Learn: Graphing Populations
Presentation
•
9th Grade
11 questions
Matrices
Presentation
•
8th - 9th Grade
Popular Resources on Wayground
20 questions
Math Review
Quiz
•
3rd Grade
15 questions
Fast food
Quiz
•
7th Grade
20 questions
Context Clues
Quiz
•
6th Grade
20 questions
Inferences
Quiz
•
4th Grade
19 questions
Classifying Quadrilaterals
Quiz
•
3rd Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
10 questions
Identify Fractions, Mixed Numbers & Improper Fractions
Quiz
•
3rd - 4th Grade
Discover more resources for Computers
10 questions
Fact Check Ice Breaker: Two truths and a lie
Quiz
•
5th - 12th Grade
10 questions
Video Games
Quiz
•
6th - 12th Grade
10 questions
Logos
Quiz
•
6th - 9th Grade
10 questions
Test Your Knowledge with 15 Fun Trivia Questions
Interactive video
•
6th - 10th Grade
15 questions
Memorial Day Trivia
Quiz
•
KG - 12th Grade
21 questions
Factoring Trinomials (a=1)
Quiz
•
9th Grade
12 questions
Name that Candy
Quiz
•
KG - 12th Grade
20 questions
Guess The App
Quiz
•
KG - Professional Dev...