Javascript Control Structures Practice

Flashcard
•
Computers
•
9th - 12th Grade
•
Hard
Wayground 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
12 questions
CE-LP1 Programação Orientadas a Objetos (POO)

Flashcard
•
KG - University
10 questions
Arrays

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

Flashcard
•
11th - 12th Grade
12 questions
java while loop

Flashcard
•
9th - 12th Grade
17 questions
Unit 7 - Functions and Parameters Review

Flashcard
•
9th - 12th Grade
8 questions
Java CH4 - Control Statements EXIT

Flashcard
•
10th - 12th Grade
10 questions
Code.org CSP Unit 5 Lists

Flashcard
•
9th - 12th Grade
6 questions
lists/tuples

Flashcard
•
9th - 12th Grade
Popular Resources on Wayground
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
Appointment Passes Review

Quiz
•
6th - 8th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
20 questions
Grammar Review

Quiz
•
6th - 9th Grade
Discover more resources for Computers
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
17 questions
[AP CSP] Binary Number System

Lesson
•
9th - 12th Grade
15 questions
1.1 Network Fundamentals Quiz

Quiz
•
10th Grade
20 questions
Understanding Information Processing Cycle

Quiz
•
10th Grade
19 questions
AP CSP Unit 1 Review (code.org)

Quiz
•
10th - 12th Grade