Javascript Control Structures Practice

Flashcard
•
Computers
•
9th - 12th Grade
•
Hard
Quizizz Content
FREE Resource
Student preview

14 questions
Show all answers
1.
FLASHCARD QUESTION
Front
What is the value of the boolean variable canVote at the end of this program?
var age = 17;
var isCitizen = true;
var canVote = age >= 18 && isCitizen;
Back
False
Answer explanation
The variable canVote is determined by the expression age >= 18 && isCitizen. Since age is 17 (not >= 18), the expression evaluates to false. Therefore, the value of canVote is False.
2.
FLASHCARD QUESTION
Front
What will be the output of this program?
var number = 5;
var greater_than_zero = number > 0;
if (greater_than_zero){
println(number);
}
Back
5
Answer explanation
The variable 'number' is set to 5. The condition 'greater_than_zero' evaluates to true since 5 > 0. Therefore, the program prints the value of 'number', which is 5.
3.
FLASHCARD QUESTION
Front
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);
}
}
Back
Nothing will print
Answer explanation
The variable 'greater_than_zero' is true since 5 > 0. However, the inner condition 'number > 5' is false, so 'println(number)' does not execute. Therefore, nothing will print.
4.
FLASHCARD QUESTION
Front
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);
Back
Is it warm: true
Answer explanation
isSunny is true because both isRaining and isCloudy are false. isWarm is true since isSunny is true, regardless of isSummer. Therefore, the output is 'Is it warm: true'.
5.
FLASHCARD QUESTION
Front
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");
Back
Hello, we are open!
Sincerely, the grocery store
Answer explanation
The condition 'numApples < 20' is true (10 < 20), so 'Hello, we are open!' is printed. The final line 'Sincerely, the grocery store' is also printed, making the correct choice: 'Hello, we are open!' and 'Sincerely, the grocery store'.
6.
FLASHCARD QUESTION
Front
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.");
}
}
Back
Almost eligible for Driver’s License
Answer explanation
The program checks if all conditions (above16, hasPermit, passedTest) are true. Since passedTest is false, it goes to the else block. One condition is true (above16), so it prints 'Almost eligible for Driver's License'.
7.
FLASHCARD QUESTION
Front
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);
}
Back
1
4
5
Answer explanation
The program prints 1 because numberOne is 5. It does not print 2 or 3 since those conditions are false. It prints 4 because numberOne (5) is less than numberTwo (10) and prints 5 because numberOne is not equal to numberTwo.
Create a free account and access millions of resources
Similar Resources on Wayground
10 questions
Arrays

Flashcard
•
10th - 12th Grade
16 questions
Loops Flashcard

Flashcard
•
9th - 12th Grade
15 questions
CodeHS Python Unit 5 Looping Flashcard

Flashcard
•
9th - 12th Grade
13 questions
CSAwesome: 1.2 - Java Basics HW Review

Flashcard
•
11th - 12th Grade
11 questions
Java Boolean Statements

Flashcard
•
11th Grade
10 questions
Ôn tập chủ đề F

Flashcard
•
KG
13 questions
Python - Unit Test 2

Flashcard
•
9th Grade - University
13 questions
Functions and Parameters

Flashcard
•
9th - 12th Grade
Popular Resources on Wayground
50 questions
Trivia 7/25

Quiz
•
12th Grade
11 questions
Standard Response Protocol

Quiz
•
6th - 8th Grade
11 questions
Negative Exponents

Quiz
•
7th - 8th Grade
12 questions
Exponent Expressions

Quiz
•
6th Grade
4 questions
Exit Ticket 7/29

Quiz
•
8th Grade
20 questions
Subject-Verb Agreement

Quiz
•
9th Grade
20 questions
One Step Equations All Operations

Quiz
•
6th - 7th Grade
18 questions
"A Quilt of a Country"

Quiz
•
9th Grade
Discover more resources for Computers
50 questions
Trivia 7/25

Quiz
•
12th Grade
20 questions
Subject-Verb Agreement

Quiz
•
9th Grade
18 questions
"A Quilt of a Country"

Quiz
•
9th Grade
6 questions
RL.10.1 Cite Evidence

Quiz
•
10th Grade
10 questions
Characteristics of Life

Quiz
•
9th - 10th Grade
14 questions
Algebra 1 SOL Review #1

Quiz
•
9th Grade