From da7719f22d2ef8b03f0b137403a1d1ad4fe66222 Mon Sep 17 00:00:00 2001 From: Patrick Wauschek Date: Thu, 25 Jul 2024 02:22:04 -0500 Subject: [PATCH] fix(curriculum): fixes pyramid range error (#55486) --- .../660f4934fb48f63abd5ae371.md | 8 +++++--- .../661483051820c3c1ab4595e0.md | 16 ++-------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-introductory-javascript-by-building-a-pyramid-generator/660f4934fb48f63abd5ae371.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-introductory-javascript-by-building-a-pyramid-generator/660f4934fb48f63abd5ae371.md index eb133b13ff8..32d011d4703 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-introductory-javascript-by-building-a-pyramid-generator/660f4934fb48f63abd5ae371.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-introductory-javascript-by-building-a-pyramid-generator/660f4934fb48f63abd5ae371.md @@ -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 elements, 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-- diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-introductory-javascript-by-building-a-pyramid-generator/661483051820c3c1ab4595e0.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-introductory-javascript-by-building-a-pyramid-generator/661483051820c3c1ab4595e0.md index 60a36a5c3c8..03a7aa88b89 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-introductory-javascript-by-building-a-pyramid-generator/661483051820c3c1ab4595e0.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-introductory-javascript-by-building-a-pyramid-generator/661483051820c3c1ab4595e0.md @@ -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)); }