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 | |
|---|---|---|
| 1scores[scores.length - 1] | AThe last index is length - 1, so this reads past the end and gives undefined. Write colours[colours.length - 1]. | |
| 2let items = []; console.log(items.length); | Blet count = names.length; | |
| 3length is a property, so it is written without brackets to give the number of items | Clength is a property, not a method, so it must not have brackets. Write fruits.length. | |
| 4The length grows when an item is added to the array | DGets the last item in the scores array, because the last index is always length - 1 | |
| 5let total = fruits.length(); | Elet pets = ['cat']; pets.push('dog'); console.log(pets.length); | |
| 6let last = colours[colours.length]; | FPrints 0, because an empty array has a length of 0 |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
array.length — A property (no brackets) giving how many items are in an array. The last index is length - 1, an empty array has length 0, and length grows as items are added.let scores = [5, 8, 9];
console.log(scores.length);let scores = [5, 8, 9];
console.log(scores[scores.length - 1]);let list = [];
console.log(list.length === 0);let pets = ["cat"];
pets.push("dog");
console.log(pets.length === 2);let nums = [4, 7, 2];
for (let i = 0; i < nums.length; i++)
console.log(nums[i]);