mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(curriculum): fixes pyramid range error (#55486)
This commit is contained in:
+5
-3
@@ -11,14 +11,16 @@ Using `done` to track the number of rows that have been generated is functional,
|
||||
|
||||
Arrays have a special `length` property that allows you to see how many values, or <dfn>elements</dfn>, are in the array. You would access this property using syntax like `myArray.length`.
|
||||
|
||||
Update your condition to check if `rows.length` is less than or equal to `count`.
|
||||
Note that `rows.length` in the `padRow` call would give you an off-by-one error, because `done` is incremented *before* the call.
|
||||
|
||||
Update your condition to check if `rows.length` is less than `count`.
|
||||
|
||||
# --hints--
|
||||
|
||||
Your `while` loop should check if `rows.length` is less than or equal to `count`.
|
||||
Your `while` loop should check if `rows.length` is less than `count`.
|
||||
|
||||
```js
|
||||
assert.match(__helpers.removeJSComments(code), /while\s*\(\s*rows\.length\s*<=\s*count\s*\)/);
|
||||
assert.match(__helpers.removeJSComments(code), /while\s*\(\s*rows\.length\s*<\s*count\s*\)/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
+2
-14
@@ -7,13 +7,7 @@ dashedName: step-96
|
||||
|
||||
# --description--
|
||||
|
||||
You can also replace the `done` reference in your `padRow` call.
|
||||
|
||||
Note that `rows.length` here would give you an off-by-one error, because `done` is incremented *before* the call.
|
||||
|
||||
So you'll need to replace `done` here with `rows.length + 1`. When you do this, you may see a `Range Error`, because we've created another off-by-one error.
|
||||
|
||||
You'll need to change the `while` condition to use the less than operator, instead of the less than or equal operator.
|
||||
Replace the `done` reference in your `padRow` call with `rows.length + 1`.
|
||||
|
||||
# --hints--
|
||||
|
||||
@@ -23,12 +17,6 @@ You should pass `rows.length + 1` as the first argument to your `padRow` call.
|
||||
assert.match(__helpers.removeJSComments(code), /rows\.push\(padRow\s*\(\s*rows\.length\s*\+\s*1/);
|
||||
```
|
||||
|
||||
Your `while` loop should run while `rows.length` is less than `count`.
|
||||
|
||||
```js
|
||||
assert.match(__helpers.removeJSComments(code), /while\s*\(\s*rows\.length\s*<\s*count\)/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
@@ -50,7 +38,7 @@ function padRow(rowNumber, rowCount) {
|
||||
--fcc-editable-region--
|
||||
let done = 0;
|
||||
|
||||
while (rows.length <= count) {
|
||||
while (rows.length < count) {
|
||||
done++;
|
||||
rows.push(padRow(done, count));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user