From 8b09caa5f8131b1704dadf4a25e35faa152dc7e4 Mon Sep 17 00:00:00 2001 From: BIgChunkyChicken <101303345+Liekmeow@users.noreply.github.com> Date: Mon, 22 Apr 2024 22:10:15 +0800 Subject: [PATCH] fix(curriculum): update description for step 19 of pyramid project (#54474) --- .../6610bbed59bc2a0194d85533.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-introductory-javascript-by-building-a-pyramid-generator/6610bbed59bc2a0194d85533.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-introductory-javascript-by-building-a-pyramid-generator/6610bbed59bc2a0194d85533.md index 92cd9dfc29c..a22b643ec99 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-introductory-javascript-by-building-a-pyramid-generator/6610bbed59bc2a0194d85533.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-introductory-javascript-by-building-a-pyramid-generator/6610bbed59bc2a0194d85533.md @@ -11,11 +11,17 @@ Notice how the value inside your `rows` array has been changed directly? This is Before moving on, this is a great opportunity to learn a common array use. Currently, your code accesses the last element in the array with `rows[2]`. But you may not know how many elements are in an array when you want the last one. -You can make use of the `.length` property of an array - this returns the number of elements in the array. For example, your `rows` array has 3 elements, so `rows.length` would be `3`. +You can make use of the `.length` property of an array - this returns the number of elements in the array. To get the last element of any array, you can use the following syntax: -Since you know the last element is at index `2`, you can compare that with the length of the array and see it is one less. The last element of an array will always be accessible at the index `length - 1`. You can use that in your bracket notation. +```js +array[array.length - 1] +``` -Update your `rows[2]` to access the `rows.length - 1` index instead of the `2` index. You should not see anything change in your console. +`array.length` returns the number of elements in the array. By subtracting `1`, you get the index of the last element in the array. You can apply this same concept to your `rows` array. + +Update your `rows[2]` to dynamically access the last element in the `rows` array. Refer to the example above to help you. + +You should not see anything change in your console. # --hints--