Javascript Control Structures Practice

Javascript Control Structures Practice

Assessment

Flashcard

Computers

9th - 12th Grade

Hard

Created by

Quizizz Content

FREE Resource

Student preview

quiz-placeholder

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

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?