Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1let largest = nums[0]; | AReplaces the current largest value when a bigger item is found in the array. | |
| 2if (nums[i] > largest) { largest = nums[i]; } | Bif (nums[i] < smallest) { smallest = nums[i]; } | |
| 3After the loop has compared every item, the function returns the largest value it found. | CThe return is inside the loop, so the function stops after the first comparison. Move it after the loop closing brace. | |
| 4To find the smallest value, start with the first item and replace it when a smaller item is found. | DStarts by treating the first item in the array as the largest value so far. | |
| 5let largest = 0; for (let i = 1; i < nums.length; i++) { if (nums[i] > largest) { largest = nums[i]; } } | EStarting at 0 fails when every number is negative, because 0 would wrongly stay as the largest. Start with nums[0] instead. | |
| 6for (let i = 1; i < nums.length; i++) { if (nums[i] > largest) { largest = nums[i]; } return largest; } | Freturn largest; |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
let largest = nums[0]; — Start by treating the first array item as the largest, compare every other item, replace it when a bigger one is found, then return it. Smallest works the same way.let largest = nums[0];if (nums[i] > largest) {
largest = nums[i];
}for (let i = 1; i < nums.length; i++) { }
return largest;
}let smallest = nums[0];
if (nums[i] < smallest) {
smallest = nums[i];