3.4.2 Find an Element in a List
10 Computer Science · Chapter 3: Programing Fundamentals · Federal Board (FBISE)
3.4.2 Find an Element in a List from Federal Board 10 Computer Science (10th Class) Chapter 3, Programing Fundamentals: 5 MCQs with answers.
Find an Element in a List MCQs
- Q1
In the "find an element" algorithm, what is the purpose of the first loop over the shopping list?
Show answer
Correct answer: D. To build and display the full list content
The first loop constructs a string of all list items to display the full shopping list on the webpage.
- Q2
In the search algorithm, what happens once a matching item is found in the second loop?
Show answer
Correct answer: B. The function returns immediately and updates the result message
Once a match is found, the function uses 'return' to stop the loop and updates the result message immediately.
- Q3
What message is displayed if the search loop completes without finding the target item?
Show answer
Correct answer: B. A message indicating the item was not found
If no match is found after the loop ends, the HTML section is updated with a message saying the item was not found.
- Q4
What does the function parameter 'itemName' represent in the findItem() function?
Show answer
Correct answer: C. The item the user wants to search for
'itemName' is the parameter that holds the value of the item being searched for in the list.
- Q5
Why is a loop necessary when searching for an item in an unsorted list?
Show answer
Correct answer: B. Because each element must be checked one at a time until a match is found
In an unsorted list, each element must be checked sequentially using a loop until the target item is found or the list ends.