FBISE, NCP & NBF-aligned resources for Classes 9–12
Browse by Class
Browse by Type
Computer Chapter 3 : Topic 4.5
Construct and populate arrays using loops
1 / 9
A student is instructed to create an empty array in JavaScript and then fill it dynamically using a loop based on user-defined size. Which approach correctly initializes the array before population?
Reasoning: Square brackets initialize an empty array, which is required before using a loop to insert values dynamically.
2 / 9
A JavaScript program uses a loop to assign values to an array where each element stores its index multiplied by 2. Which statement best describes this process?
Reasoning: The loop generates values based on a formula, showing dynamic population rather than fixed assignment.
3 / 9
In a program, a student uses a for loop to fill an array of size 5 with values entered by the user. Why is a loop preferred over writing individual assignments?
Reasoning: Loops automate repetition, making it efficient for filling arrays of any size.
4 / 9
Which JavaScript loop structure is most appropriate when constructing an array by assigning values to each index from 0 to n-1?
Reasoning: A for loop is ideal for index-based iteration when filling arrays sequentially.
5 / 9
A program initializes an empty array and then uses arr[i] = i + 1 inside a loop. What is the main effect of this statement?
Reasoning: The statement assigns values directly to array indices during loop execution.
6 / 9
A student writes a loop that runs from i = 0 to i < 10 and stores i * i into an array. What type of data is being stored in the array?
Reasoning: Each element is calculated as i squared, meaning the array stores computed values based on index.
7 / 9
While constructing an array using a loop, a programmer mistakenly starts the loop from i = 1 instead of i = 0. What is the most likely outcome?
Reasoning: Since JavaScript arrays start at index 0, starting from 1 leaves index 0 empty or undefined.
8 / 9
A JavaScript program uses a loop to populate an array and later prints all elements using another loop. Which concept is primarily demonstrated here?
Reasoning: The program follows sequence for steps and repetition for both filling and displaying the array.
9 / 9
A teacher asks students to store numbers 1 to 100 in an array using a loop instead of manual entry. What is the key advantage of this method?
Reasoning: Using loops automates repetitive tasks, reducing mistakes and improving efficiency.
Your score is
Restart quiz