
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
10 questions
1.02 (Distributive Property)
Presentation
•
9th Grade
11 questions
Mastering Word Processing
Presentation
•
9th Grade
11 questions
Physical computing
Presentation
•
9th Grade
11 questions
Systems of Equations Word Problems
Presentation
•
8th - 9th Grade
12 questions
Computations with Scientific Notation
Presentation
•
8th - 9th Grade
11 questions
Linear Equation in two variable
Presentation
•
9th Grade
11 questions
Google Sheets Basics lesson
Presentation
•
9th Grade
11 questions
1.3 Day 1 Solving Eq. with Variable on both Sides
Presentation
•
9th Grade
Popular Resources on Wayground
24 questions
PBIS-HGMS Day 10
Quiz
•
6th - 8th Grade
10 questions
HCS SCI 03 Summer School Review 3
Quiz
•
3rd Grade
11 questions
Home Scope
Quiz
•
7th - 8th Grade
15 questions
HCS SCI 05 Summer School Assessment 3 Review
Quiz
•
5th Grade
35 questions
Lufkin Road Middle School Student Handbook & Policies Assessment
Quiz
•
7th Grade
18 questions
Geo 11.3 Area of Circles and Sectors
Quiz
•
9th - 11th Grade