JavaScript Control Flow and Loops.

Quiz
•
Computers
•
10th Grade
•
Medium
Curriculum Team
Used 2+ times
FREE Resource
35 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
2 mins • 2 pts
What is the basic syntax of an if statement in JavaScript?
if { condition } // code to execute
if (condition) // code to execute
if condition { // code to execute }
if (condition) { // code to execute }
Answer explanation
The correct syntax for an if statement in JavaScript is 'if (condition) { // code to execute }'. This format includes parentheses around the condition and curly braces for the code block, making it the proper structure.
2.
MULTIPLE CHOICE QUESTION
2 mins • 2 pts
How does an else if statement differ from a simple if statement?
An 'else if' statement can check multiple conditions, while a simple 'if' statement checks only one.
An 'else if' statement is used only in loops.
An 'else if' statement cannot be used in nested conditions.
A simple 'if' statement can check multiple conditions.
Answer explanation
An 'else if' statement allows for checking multiple conditions in sequence, while a simple 'if' statement evaluates only one condition at a time. This makes 'else if' useful for handling complex decision-making scenarios.
3.
MULTIPLE CHOICE QUESTION
2 mins • 2 pts
Provide an example of a switch statement that checks for a day of the week.
switch(day) { case 'Monday': console.log('Start of the week'); break; case 'Tuesday': console.log('Second day of the week'); break; case 'Wednesday': console.log('Midweek'); break; case 'Thursday': console.log('Almost there'); break; case 'Friday': console.log('End of the work week'); break; case 'Saturday': console.log('Weekend!'); break; case 'Sunday': console.log('Rest day'); break; default: console.log('Invalid day'); }
switch(day) { case 'January': console.log('Start of the year'); break; }
switch(day) { case 'Monday': console.log('Midweek'); break; }
switch(day) { case 'Friday': console.log('Start of the weekend'); break; }
Answer explanation
The correct switch statement checks for all days of the week, providing specific messages for each day. The other options either check for a month or incorrectly label days, making them invalid for the question.
4.
MULTIPLE CHOICE QUESTION
2 mins • 2 pts
What will the following code output? if (x === 5) { console.log('Five'); } else { console.log('Not Five'); }
'Not Five' if x is 5
Depends on the value of x; 'Five' if x is 5, 'Not Five' otherwise.
'Five' if x is 0
'Five' if x is greater than 5
Answer explanation
The code checks if x is exactly 5. If true, it logs 'Five'; otherwise, it logs 'Not Five'. Thus, the output depends on the value of x: 'Five' if x is 5, 'Not Five' otherwise.
5.
MULTIPLE CHOICE QUESTION
2 mins • 2 pts
In a for loop, what are the three main components in the initialization, condition, and increment sections?
Setup, Check, Update
Initialization, Condition, Increment
Start, Test, Finish
Begin, Evaluate, Modify
Answer explanation
In a for loop, the three main components are Initialization (setting up the loop variable), Condition (the test that determines if the loop continues), and Increment (updating the loop variable). Thus, the correct answer is 'Initialization, Condition, Increment'.
6.
MULTIPLE CHOICE QUESTION
2 mins • 2 pts
What is the purpose of a while loop in JavaScript?
To create a new variable in JavaScript.
To stop the execution of a program in JavaScript.
To define a function in JavaScript.
The purpose of a while loop in JavaScript is to execute a block of code repeatedly as long as a specified condition is true.
Answer explanation
A while loop in JavaScript is used to repeatedly execute a block of code as long as a specified condition remains true, making it essential for tasks that require iteration until a certain condition is met.
7.
MULTIPLE CHOICE QUESTION
2 mins • 2 pts
Write a simple function declaration that takes two parameters and returns their sum.
function total(a, b) { return a / b; }
function addNumbers(x, y) { return x * y; }
function sum(a, b) { return a - b; }
function add(a, b) { return a + b; }
Answer explanation
The correct function is 'function add(a, b) { return a + b; }' because it properly takes two parameters and returns their sum. The other options use incorrect operations (division, multiplication, subtraction) instead of addition.
Create a free account and access millions of resources
Similar Resources on Wayground
30 questions
ASHV 2k23 Quizzing

Quiz
•
University
39 questions
Access Modifiers, Inheritance & Polymorphism

Quiz
•
University
40 questions
JavaScript - Avaliação

Quiz
•
10th - 12th Grade
39 questions
Advanced Object Oriented Programming

Quiz
•
University
30 questions
Programming launchpad: JS practice

Quiz
•
12th Grade
40 questions
Takeshi's Castle Rapid Fire

Quiz
•
University
40 questions
Android Development Associate

Quiz
•
University
40 questions
Kisi kisi soal Pemrograman Berorientasi Objek

Quiz
•
11th 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
9/11 Experience and Reflections

Interactive video
•
10th - 12th 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
9 questions
Tips & Tricks

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

Interactive video
•
6th - 10th Grade
10 questions
1.2 OSI & TCP IP Models Quiz

Quiz
•
10th Grade
20 questions
Digital Citizenship

Quiz
•
8th - 12th Grade
35 questions
Computer Baseline Examination 2025-26

Quiz
•
9th - 12th Grade
13 questions
Problem Solving Process

Quiz
•
9th - 12th Grade
20 questions
Hardware vs. Software Quiz

Quiz
•
7th - 10th Grade
10 questions
Understanding Algorithms with Pseudocode and Flowcharts

Interactive video
•
9th - 12th Grade
19 questions
AP CSP Unit 1 Review (code.org)

Quiz
•
10th - 12th Grade