feat: new introductory javascript project (#54305)

Co-authored-by: Sem Bauke <semboot699@gmail.com>
Co-authored-by: Jessica Wilkins <67210629+jdwilkin4@users.noreply.github.com>
Co-authored-by: Kolade Chris <65571316+Ksound22@users.noreply.github.com>
This commit is contained in:
Naomi
2024-04-17 09:29:14 -07:00
committed by GitHub
parent 2461a82093
commit d6835ef8b7
135 changed files with 7134 additions and 43 deletions
+7
View File
@@ -458,6 +458,13 @@
"Recursion is a programming concept where a function calls itself. This can reduce a complex problem into simpler sub-problems, until they become straightforward to solve.",
"In this project, youll build a decimal-to-binary converter using JavaScript. Youll learn the fundamental concepts of recursion, explore the call stack, and build out a visual representation of the recursion process through an animation."
]
},
"learn-introductory-javascript-by-building-a-pyramid-generator": {
"title": "Learn Introductory JavaScript by Building a Pyramid Generator",
"intro": [
"JavaScript is a powerful scripting language that you can use to make web pages interactive. It's one of the core technologies of the web, along with HTML and CSS. All modern browsers support JavaScript.",
"In this practice project, you'll learn fundamental programming concepts in JavaScript by coding your own Pyramid Generator. You'll learn how to work with arrays, strings, functions, loops, <code>if/else</code> statements, and more."
]
}
}
},
@@ -0,0 +1,10 @@
---
title: Introduction to the Learn Introductory JavaScript by Building a Pyramid Generator
block: learn-introductory-javascript-by-building-a-pyramid-generator
superBlock: javascript-algorithms-and-data-structures-v8
isBeta: true
---
## Introduction to the Learn Introductory JavaScript by Building a Pyramid Generator
This is a test for the new project-based curriculum.
@@ -4,7 +4,7 @@
"dashedName": "build-a-cash-register-project",
"usesMultifileEditor": true,
"helpCategory": "JavaScript",
"order": 17,
"order": 18,
"time": "30 hours",
"template": "",
"required": [],
@@ -15,4 +15,4 @@
"title": "Build a Cash Register"
}
]
}
}
@@ -4,7 +4,7 @@
"dashedName": "build-a-palindrome-checker-project",
"usesMultifileEditor": true,
"helpCategory": "JavaScript",
"order": 4,
"order": 5,
"time": "30 hours",
"template": "",
"required": [],
@@ -15,4 +15,4 @@
"title": "Build a Palindrome Checker"
}
]
}
}
@@ -4,7 +4,7 @@
"dashedName": "build-a-pokemon-search-app-project",
"usesMultifileEditor": true,
"helpCategory": "JavaScript",
"order": 20,
"order": 21,
"time": "30 hours",
"template": "",
"required": [],
@@ -15,4 +15,4 @@
"title": "Build a Pokémon Search App Project"
}
]
}
}
@@ -4,7 +4,7 @@
"dashedName": "build-a-roman-numeral-converter-project",
"usesMultifileEditor": true,
"helpCategory": "JavaScript",
"order": 8,
"order": 9,
"time": "30 hours",
"template": "",
"required": [],
@@ -15,4 +15,4 @@
"title": "Build a Roman Numeral Converter"
}
]
}
}
@@ -4,7 +4,7 @@
"dashedName": "build-a-telephone-number-validator-project",
"usesMultifileEditor": true,
"helpCategory": "JavaScript",
"order": 13,
"order": 14,
"time": "30 hours",
"template": "",
"required": [],
@@ -15,4 +15,4 @@
"title": "Build a Telephone Number Validator"
}
]
}
}
@@ -5,7 +5,7 @@
"hasEditableBoundaries": true,
"dashedName": "learn-advanced-array-methods-by-building-a-statistics-calculator",
"helpCategory": "JavaScript",
"order": 11,
"order": 12,
"time": "5 hours",
"template": "",
"required": [],
@@ -234,4 +234,4 @@
"title": "Step 55"
}
]
}
}
@@ -5,7 +5,7 @@
"hasEditableBoundaries": true,
"dashedName": "learn-asynchronous-programming-by-building-an-fcc-forum-leaderboard",
"helpCategory": "JavaScript",
"order": 19,
"order": 20,
"time": "5 hours",
"template": "",
"required": [],
@@ -280,4 +280,4 @@
"title": "Step 67"
}
]
}
}
@@ -5,7 +5,7 @@
"hasEditableBoundaries": true,
"dashedName": "learn-basic-algorithmic-thinking-by-building-a-number-sorter",
"helpCategory": "JavaScript",
"order": 10,
"order": 11,
"time": "5 hours",
"template": "",
"required": [],
@@ -182,4 +182,4 @@
"title": "Step 42"
}
]
}
}
@@ -5,7 +5,7 @@
"hasEditableBoundaries": true,
"dashedName": "learn-basic-javascript-by-building-a-role-playing-game",
"helpCategory": "JavaScript",
"order": 0,
"order": 1,
"time": "2 hours",
"template": "",
"required": [],
@@ -729,4 +729,4 @@
"title": "Step 179"
}
]
}
}
@@ -5,7 +5,7 @@
"hasEditableBoundaries": true,
"dashedName": "learn-basic-oop-by-building-a-shopping-cart",
"helpCategory": "JavaScript",
"order": 14,
"order": 15,
"time": "5 hours",
"template": "",
"required": [],
@@ -254,4 +254,4 @@
"title": "Step 60"
}
]
}
}
@@ -4,7 +4,7 @@
"usesMultifileEditor": true,
"hasEditableBoundaries": true,
"dashedName": "learn-basic-string-and-array-methods-by-building-a-music-player",
"order": 2,
"order": 3,
"time": "5 hours",
"template": "",
"required": [],
@@ -410,4 +410,4 @@
}
],
"helpCategory": "JavaScript"
}
}
@@ -5,7 +5,7 @@
"hasEditableBoundaries": true,
"dashedName": "learn-fetch-and-promises-by-building-an-fcc-authors-page",
"helpCategory": "JavaScript",
"order": 18,
"order": 19,
"time": "5 hours",
"template": "",
"required": [],
@@ -130,4 +130,4 @@
"title": "Step 29"
}
]
}
}
@@ -5,7 +5,7 @@
"hasEditableBoundaries": true,
"dashedName": "learn-form-validation-by-building-a-calorie-counter",
"helpCategory": "JavaScript",
"order": 1,
"order": 2,
"time": "2 hours",
"template": "",
"required": [],
@@ -396,4 +396,4 @@
"title": "Step 96"
}
]
}
}
@@ -5,7 +5,7 @@
"hasEditableBoundaries": true,
"dashedName": "learn-functional-programming-by-building-a-spreadsheet",
"helpCategory": "JavaScript",
"order": 12,
"order": 13,
"time": "2 hours",
"template": "",
"required": [],
@@ -426,4 +426,4 @@
"title": "Step 103"
}
]
}
}
@@ -4,7 +4,7 @@
"usesMultifileEditor": true,
"hasEditableBoundaries": true,
"dashedName": "learn-intermediate-algorithmic-thinking-by-building-a-dice-game",
"order": 16,
"order": 17,
"time": "5 hours",
"template": "",
"required": [],
@@ -5,7 +5,7 @@
"hasEditableBoundaries": true,
"dashedName": "learn-intermediate-oop-by-building-a-platformer-game",
"helpCategory": "JavaScript",
"order": 15,
"order": 16,
"time": "5 hours",
"template": "",
"required": [],
@@ -484,4 +484,4 @@
"title": "Step 117"
}
]
}
}
@@ -0,0 +1,453 @@
{
"name": "Learn Introductory JavaScript by Building a Pyramid Generator",
"isUpcomingChange": false,
"usesMultifileEditor": true,
"hasEditableBoundaries": true,
"dashedName": "learn-introductory-javascript-by-building-a-pyramid-generator",
"order": 0,
"time": "5 hours",
"template": "",
"required": [],
"superBlock": "javascript-algorithms-and-data-structures-v8",
"superOrder": 4,
"isBeta": true,
"challengeOrder": [
{
"id": "660ee6e3a242da6bd579de69",
"title": "Step 1"
},
{
"id": "660eebd83100d37862268781",
"title": "Step 2"
},
{
"id": "660ef0f7c4b8e68ccd1f0786",
"title": "Step 3"
},
{
"id": "660ef19b95d3308e7dd31bb6",
"title": "Step 4"
},
{
"id": "660ef31a5be625914a0102cd",
"title": "Step 5"
},
{
"id": "660ef5105b8ba095307a0e50",
"title": "Step 6"
},
{
"id": "6610b741b54b90f0c0fb3d58",
"title": "Step 7"
},
{
"id": "6610b8017d1671f2814e8c77",
"title": "Step 8"
},
{
"id": "6610b8f6a98d25f4d485a94d",
"title": "Step 9"
},
{
"id": "6610b9f7619764fad5fd516d",
"title": "Step 10"
},
{
"id": "660ef55dd468079679ee0092",
"title": "Step 11"
},
{
"id": "660ef5c1904955978a986a5c",
"title": "Step 12"
},
{
"id": "660ef6355e8f5a9e67fe5f46",
"title": "Step 13"
},
{
"id": "660ef857f2806aa626d29d17",
"title": "Step 14"
},
{
"id": "660f033cf051ebb50ea3bf48",
"title": "Step 15"
},
{
"id": "660f039ff313dbb696b007ca",
"title": "Step 16"
},
{
"id": "660f061d259bbebc37461080",
"title": "Step 17"
},
{
"id": "660f07d231941bc11719f664",
"title": "Step 18"
},
{
"id": "6610bbed59bc2a0194d85533",
"title": "Step 19"
},
{
"id": "660f09a2694b59c3a10ee304",
"title": "Step 20"
},
{
"id": "660f0a55847d6cc485f29ba5",
"title": "Step 21"
},
{
"id": "660f0c34aad72dc712b97624",
"title": "Step 22"
},
{
"id": "660f0da9bf1035c9097af20a",
"title": "Step 23"
},
{
"id": "660f0ee51d7460ce88cd248d",
"title": "Step 24"
},
{
"id": "660f0f980e98e8cf77f1ce31",
"title": "Step 25"
},
{
"id": "660f165270622fd4ec0da3f7",
"title": "Step 26"
},
{
"id": "660f17294346b7d69e79db3d",
"title": "Step 27"
},
{
"id": "660f17d4e9f227d86e834abd",
"title": "Step 28"
},
{
"id": "660f18f059fe0fda192ce394",
"title": "Step 29"
},
{
"id": "660f1a00ac619ddc1e259a66",
"title": "Step 30"
},
{
"id": "660f1b6e60bd9edf902c81fd",
"title": "Step 31"
},
{
"id": "660f1bf673487ae0bb25b900",
"title": "Step 32"
},
{
"id": "660f1cedf3676fe26122ebf6",
"title": "Step 33"
},
{
"id": "660f1e3f047bf4e403268713",
"title": "Step 34"
},
{
"id": "660f20473aef47e9b8c9afc6",
"title": "Step 35"
},
{
"id": "660f207334fabaeac3269c38",
"title": "Step 36"
},
{
"id": "660f229d2dbe09ef2954a4a1",
"title": "Step 37"
},
{
"id": "660f23b53db70af0f2620e78",
"title": "Step 38"
},
{
"id": "660f255022991ef34ed0ee88",
"title": "Step 39"
},
{
"id": "660f280dda5040f707c76b4a",
"title": "Step 40"
},
{
"id": "660f2a70ad6225fa503e71c3",
"title": "Step 41"
},
{
"id": "660f2b6fd54ac1fc142804dd",
"title": "Step 42"
},
{
"id": "6610c105bbdacc114d6cdc44",
"title": "Step 43"
},
{
"id": "6610c16c4fa0df12c0e30675",
"title": "Step 44"
},
{
"id": "6610c1d97b1671140f95cfbb",
"title": "Step 45"
},
{
"id": "6610c21b3ef82015573ffbbe",
"title": "Step 46"
},
{
"id": "6610c2d8d67563174fcf96dc",
"title": "Step 47"
},
{
"id": "6610c424b7119919b62932f4",
"title": "Step 48"
},
{
"id": "6610c48c4ea0891afa7c4696",
"title": "Step 49"
},
{
"id": "6610c538372aa61cc0f5b122",
"title": "Step 50"
},
{
"id": "6610c6541c82551f95e765ab",
"title": "Step 51"
},
{
"id": "6610c71600966a2191d3a64a",
"title": "Step 52"
},
{
"id": "6610c77d50636722e5b6be17",
"title": "Step 53"
},
{
"id": "6610c83b52583e245a079217",
"title": "Step 54"
},
{
"id": "6610c87eac0f0b256d7b037e",
"title": "Step 55"
},
{
"id": "6610c8cfe4cf4d278e35c156",
"title": "Step 56"
},
{
"id": "660f2eccfe3f820304af1b39",
"title": "Step 57"
},
{
"id": "660f2fbd45b520046cac68e8",
"title": "Step 58"
},
{
"id": "660f34626216270c682e2f7b",
"title": "Step 59"
},
{
"id": "660f34e99571070d56d2f231",
"title": "Step 60"
},
{
"id": "660f359af3e32e0f1a6880b7",
"title": "Step 61"
},
{
"id": "660f374d532dc41189cc9cc2",
"title": "Step 62"
},
{
"id": "660f383d4c772c12ff59904b",
"title": "Step 63"
},
{
"id": "660f38c34a4de6141c0c369f",
"title": "Step 64"
},
{
"id": "660f3915b41a441537ec9f5e",
"title": "Step 65"
},
{
"id": "660f39b444fd6f16d1e49c1f",
"title": "Step 66"
},
{
"id": "660f3b664421471aa595170f",
"title": "Step 67"
},
{
"id": "660f3ba3cceef11b6ba08b59",
"title": "Step 68"
},
{
"id": "660f3ce51f70571e1c5227c8",
"title": "Step 69"
},
{
"id": "660f3dd626be3a1ffe27e5d1",
"title": "Step 70"
},
{
"id": "660f415b76859a2736771607",
"title": "Step 71"
},
{
"id": "660f4377a359972c521d3f4b",
"title": "Step 72"
},
{
"id": "660f4455f457ef2e3ec6920f",
"title": "Step 73"
},
{
"id": "660f447efc0e722f016c1be0",
"title": "Step 74"
},
{
"id": "660f44f10ea40f300b896a5e",
"title": "Step 75"
},
{
"id": "660f455b044d3230ed971e98",
"title": "Step 76"
},
{
"id": "660f45ccf4ca5c31f253005a",
"title": "Step 77"
},
{
"id": "6610bf6fa14d700beed1b109",
"title": "Step 78"
},
{
"id": "660f46460f9c36330ebc07d8",
"title": "Step 79"
},
{
"id": "660f46b9c417a8341729a3ab",
"title": "Step 80"
},
{
"id": "660f4774e3e0df35a68bb5f2",
"title": "Step 81"
},
{
"id": "660f47afe4c98536715d5fa4",
"title": "Step 82"
},
{
"id": "660f487dc0c8fa38084f9754",
"title": "Step 83"
},
{
"id": "660f48a419b40238e2b8b4d5",
"title": "Step 84"
},
{
"id": "660f48e1d3682f39e81843c4",
"title": "Step 85"
},
{
"id": "660f4934fb48f63abd5ae371",
"title": "Step 86"
},
{
"id": "661483051820c3c1ab4595e0",
"title": "Step 87"
},
{
"id": "660f4990b1caa03b9dc97a43",
"title": "Step 88"
},
{
"id": "660f49e32001983c90b75850",
"title": "Step 89"
},
{
"id": "660f4a1472f8e63d76162ce5",
"title": "Step 90"
},
{
"id": "660f4a83373de83ea101685f",
"title": "Step 91"
},
{
"id": "660f4ae5b3924c3fc3373973",
"title": "Step 92"
},
{
"id": "660f4b33e2a3364094ecb540",
"title": "Step 93"
},
{
"id": "660f4b641290da41b2cf0dd9",
"title": "Step 94"
},
{
"id": "660f4c3b01c44743719c99e4",
"title": "Step 95"
},
{
"id": "660f4cde8dd305450514a1cb",
"title": "Step 96"
},
{
"id": "660f4cffb1459d45e34902d1",
"title": "Step 97"
},
{
"id": "660f4de78f775e480ba2e451",
"title": "Step 98"
},
{
"id": "660f4e74f7fd3f4a99ac2e50",
"title": "Step 99"
},
{
"id": "660f4efcb8068e4cb470dca1",
"title": "Step 100"
},
{
"id": "660f4f79e2a82a4e92290f44",
"title": "Step 101"
},
{
"id": "660f505d02b2bd513a1c3468",
"title": "Step 102"
},
{
"id": "660f50a21fe7645252804f2b",
"title": "Step 103"
},
{
"id": "660f5179b3b0ca558f6b4d4f",
"title": "Step 104"
},
{
"id": "660f51f1df0a8757934a5796",
"title": "Step 105"
},
{
"id": "660f530d6e33d159e1bf4947",
"title": "Step 106"
},
{
"id": "660f535ec33a285b33af3774",
"title": "Step 107"
},
{
"id": "660f53ad3d39175c5d4335ac",
"title": "Step 108"
},
{
"id": "660f540c2176ea5dec01306d",
"title": "Step 109"
}
],
"helpCategory": "JavaScript"
}
@@ -4,7 +4,7 @@
"usesMultifileEditor": true,
"hasEditableBoundaries": true,
"dashedName": "learn-localstorage-by-building-a-todo-app",
"order": 6,
"order": 7,
"time": "5 hours",
"template": "",
"required": [],
@@ -274,4 +274,4 @@
}
],
"helpCategory": "JavaScript"
}
}
@@ -5,7 +5,7 @@
"hasEditableBoundaries": true,
"dashedName": "learn-modern-javascript-methods-by-building-football-team-cards",
"helpCategory": "JavaScript",
"order": 5,
"order": 6,
"time": "5 hours",
"template": "",
"required": [],
@@ -202,4 +202,4 @@
"title": "Step 47"
}
]
}
}
@@ -5,7 +5,7 @@
"hasEditableBoundaries": true,
"dashedName": "learn-recursion-by-building-a-decimal-to-binary-converter",
"helpCategory": "JavaScript",
"order": 7,
"order": 8,
"superOrder": 6,
"time": "5 hours",
"template": "",
@@ -450,4 +450,4 @@
"title": "Step 109"
}
]
}
}
@@ -5,7 +5,7 @@
"hasEditableBoundaries": true,
"dashedName": "learn-regular-expressions-by-building-a-spam-filter",
"helpCategory": "JavaScript",
"order": 9,
"order": 10,
"time": "5 hours",
"template": "",
"required": [],
@@ -154,4 +154,4 @@
"title": "Step 35"
}
]
}
}
@@ -4,7 +4,7 @@
"usesMultifileEditor": true,
"hasEditableBoundaries": true,
"dashedName": "learn-the-date-object-by-building-a-date-formatter",
"order": 3,
"order": 4,
"time": "5 hours",
"template": "",
"required": [],
@@ -130,4 +130,4 @@
}
],
"helpCategory": "JavaScript"
}
}
@@ -0,0 +1,60 @@
---
id: 660ee6e3a242da6bd579de69
title: Step 1
challengeType: 0
dashedName: step-1
---
# --description--
JavaScript is the programming language that powers the web. Unlike the HTML and CSS you have learned previously, JavaScript is most commonly used to write logic instead of markup.
One of the most important concepts in programming is variables. A <dfn>variable</dfn> points to a specific memory address that stores a value. Variables are given a name which can be used throughout your code to access that value.
Declaring a variable means giving it a name. In JavaScript, this is often done with the `let` keyword. For example, here is how you would declare a `hello` variable:
```js
let hello;
```
Variable naming follows specific rules: names can include letters, numbers, dollar signs, and underscores, but cannot contain spaces and must not begin with a number.
Declare a `character` variable in your code.
_Note_: It is common practice to end statements in JavaScript with a semicolon. `;`
# --hints--
You should use `let` in your code.
```js
assert.match(code, /let/);
```
You should use `character` in your code.
```js
assert.match(code, /character/);
```
You should use `let` to declare a `character` variable.
```js
assert.match(code, /let\s+character/);
```
Your declaration should end with a semi-colon.
```js
assert.match(code, /let\s+character;/);
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
--fcc-editable-region--
```
@@ -0,0 +1,54 @@
---
id: 660eebd83100d37862268781
title: Step 2
challengeType: 0
dashedName: step-2
---
# --description--
Your `character` variable currently does not have a value. You can assign a value using the <dfn>assignment</dfn> operator `=`. For example:
```js
let hello = "Hello";
```
Assigning a value to a variable at the moment of its declaration is known as <dfn>initialization</dfn>.
Initialize your `character` variable by assigning it the value `"Hello"` during its declaration.
# --hints--
You should use the assignment operator `=`.
```js
assert.match(code, /let\s+character\s*=/);
```
You should use the string `"Hello"`.
```js
assert.match(code, /('|")Hello\1/);
```
You should use double quotes for your `"Hello"` string.
```js
assert.match(code, /"Hello"/);
```
You should assign `"Hello"` to your `character` variable.
```js
assert.equal(character, "Hello");
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
let character;
--fcc-editable-region--
```
@@ -0,0 +1,57 @@
---
id: 660ef0f7c4b8e68ccd1f0786
title: Step 3
challengeType: 0
dashedName: step-3
---
# --description--
JavaScript has seven primitive data types, with `String` being one of them. In JavaScript, a <dfn>string</dfn> represents a sequence of characters and can be enclosed in either single (`'`) or double (`"`) quotes.
Note that strings are <dfn>immutable</dfn>, which means once they are created, they cannot be changed.
Change your `"Hello"` string to use single quotes.
# --hints--
You should not have double quotes in your code.
```js
assert.notMatch(code, /"/);
```
You should use single quotes for your `"Hello"` string.
```js
assert.match(code, /'Hello'/);
```
You should still use `let` in your code.
```js
assert.match(code, /let/);
```
You should still declare a `character` variable.
```js
assert.match(code, /let\s+character/);
```
Your `character` variable should still have the string `"Hello"` for its value.
```js
assert.equal(character, "Hello");
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
let character = "Hello";
--fcc-editable-region--
```
@@ -0,0 +1,57 @@
---
id: 660ef19b95d3308e7dd31bb6
title: Step 4
challengeType: 0
dashedName: step-4
---
# --description--
The <dfn>console</dfn> allows you to print and view JavaScript output. You can send information to the console using `console.log()`. For example, this code will print `"Naomi"` to the console:
```js
let developer = "Naomi";
console.log(developer);
```
The code above accesses the `developer` variable with its name in the `console.log()`. Note that the value between the parentheses is the value that will be printed.
Print the value of the `character` variable to the console. Then, click the "Console" button to view the JavaScript console.
# --hints--
You should access the `console` in your code.
```js
assert.match(code, /console/);
```
You should access the `log` property of the `console`.
```js
assert.match(code, /console\.log/);
```
You should use parentheses to call the `.log()` method.
```js
assert.match(code, /console\.log\(/);
```
You should print the `character` variable to the console.
```js
assert.match(code, /console\.log\(\s*character\s*\)/);
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
let character = 'Hello';
--fcc-editable-region--
```
@@ -0,0 +1,64 @@
---
id: 660ef31a5be625914a0102cd
title: Step 5
challengeType: 0
dashedName: step-5
---
# --description--
When a variable is declared with the `let` keyword, you can <dfn>reassign</dfn> (or change the value of) that variable later on. In this example, the value of `programmer` is changed from `"Naomi"` to `"CamperChan"`.
```js
let programmer = "Naomi";
programmer = "CamperChan";
```
Note that when reassigning a variable that has already been declared, you do **not** use the `let` keyword.
After your `console.log`, assign the value `"World"` to your `character` variable.
# --hints--
You should use `character` twice in your code.
```js
assert.lengthOf(code.match(/character/g), 3);
```
You should use the assignment operator to reassign `character`.
```js
assert.lengthOf(code.match(/character\s*\=/g), 2);
```
You should use the string `"World"` in your code.
```js
assert.match(code, /("|')World\1/);
```
Your `character` variable should have the value `"World"`.
```js
assert.equal(character, "World");
```
Your reassignment should not use `let`.
```js
assert.isBelow(code.match(/let/g).length, 2);
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
let character = 'Hello';
console.log(character);
--fcc-editable-region--
```
@@ -0,0 +1,44 @@
---
id: 660ef5105b8ba095307a0e50
title: Step 6
challengeType: 0
dashedName: step-6
---
# --description--
Now log your `character` variable to the console again. You should see the string `"Hello"`, then the string `"World"`, in the console.
# --hints--
You should use `console.log` a second time.
```js
assert.lengthOf(code.match(/console\.log/g), 2);
```
You should log `character` to the console a second time.
```js
assert.lengthOf(code.match(/console\.log\(\s*character\s*\)/g), 2);
```
Your new `console.log()` should come after your reassignment.
```js
const reassign = code.split(/\n+/).findIndex(l => l.match(/character\s+=\s+("|')World\1/));
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
let character = 'Hello';
console.log(character);
character = "World";
--fcc-editable-region--
```
@@ -0,0 +1,53 @@
---
id: 660ef55dd468079679ee0092
title: Step 11
challengeType: 0
dashedName: step-11
---
# --description--
You are now ready to declare your next variable. Remove both `console.log` statements, and the `character` reassignment.
Also remove your `secondCharacter` variable, but leave the `character` initialization unchanged.
# --hints--
You should not have any `console.log()` statements in your code.
```js
assert.notMatch(code, /console/);
```
You should not reassign the value of `character`.
```js
assert.isAtMost(code.match(/character/).length, 1);
```
Your `character` variable should have the value `"Hello"`.
```js
assert.equal(character, "Hello");
```
You should not have a `secondCharacter` variable.
```js
assert.notMatch(code, /secondCharacter/);
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
let character = 'Hello';
console.log(character);
character = "World";
let secondCharacter;
secondCharacter = character;
console.log(secondCharacter);
--fcc-editable-region--
```
@@ -0,0 +1,46 @@
---
id: 660ef5c1904955978a986a5c
title: Step 12
challengeType: 0
dashedName: step-12
---
# --description--
Use `let` to declare a `count` variable. Assign it the <dfn>number</dfn> `8`. When using a number value, you do not use quotes. For example:
```js
let money = 100;
```
# --hints--
You should have a second `let` keyword in your code.
```js
assert.lengthOf(code.match(/let/g), 2);
```
You should use `let` to declare a `count` variable.
```js
assert.match(code, /let\s+count/);
```
You should assign the number `8` to your `count` variable.
```js
assert.equal(count, 8);
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
let character = 'Hello';
--fcc-editable-region--
```
@@ -0,0 +1,42 @@
---
id: 660ef6355e8f5a9e67fe5f46
title: Step 13
challengeType: 0
dashedName: step-13
---
# --description--
With the `number` data type, you can perform mathematical operations, like addition. Try printing `count + 1` to the console.
# --hints--
You should access the `console` in your code.
```js
assert.match(code, /console/);
```
You should access the `.log()` of the `console`.
```js
assert.match(code, /console\.log/);
```
You should log `count + 1` to the console.
```js
assert.match(code, /console\.log\(\s*count\s*\+\s*1\s*\);?/);
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
let character = 'Hello';
let count = 8;
--fcc-editable-region--
```
@@ -0,0 +1,42 @@
---
id: 660ef857f2806aa626d29d17
title: Step 14
challengeType: 0
dashedName: step-14
---
# --description--
You can also perform subtraction (`-`), multiplication (`*`), and division (`/`). Feel free to experiment with the operators and numbers in your `console.log`. When you are ready to move on, remove the `console.log`.
# --hints--
You should not have a `console.log()` in your code.
```js
assert.notMatch(code, /console/);
```
Your `character` variable should still have the value `"Hello"`.
```js
assert.equal(character, "Hello");
```
Your `count` variable should still have the value `8`.
```js
assert.equal(count, 8);
```
# --seed--
## --seed-contents--
```js
let character = 'Hello';
--fcc-editable-region--
let count = 8;
console.log(count + 1);
--fcc-editable-region--
```
@@ -0,0 +1,53 @@
---
id: 660f033cf051ebb50ea3bf48
title: Step 15
challengeType: 0
dashedName: step-15
---
# --description--
In programming, you will often need to work with lots of data. There are many data structures that can help you organize and manage your data. One of the most basic data structures is an <dfn>array</dfn>.
An <dfn>array</dfn> is a non-primitive data type that can hold a series of values. Non-primitive data types differ from primitive data types in that they can hold more complex data. Primitive data types like strings and numbers can only hold one value at a time.
Arrays are denoted using square brackets (`[]`). Here is an example of a variable with the value of an empty array:
```js
let array = [];
```
Declare a `rows` variable and assign it an empty array.
# --hints--
You should have a `rows` variable.
```js
assert.match(code, /rows/);
```
You should use `let` to declare your `rows` variable.
```js
assert.match(code, /let\s+rows/);
```
You should assign an empty array to your `rows` variable.
```js
assert.deepEqual(rows, []);
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
let character = 'Hello';
let count = 8;
--fcc-editable-region--
```
@@ -0,0 +1,48 @@
---
id: 660f039ff313dbb696b007ca
title: Step 16
challengeType: 0
dashedName: step-16
---
# --description--
When an array holds values, or <dfn>elements</dfn>, those values are separated by commas. Here is an array that holds two strings:
```js
let array = ["first", "second"];
```
Change your `rows` declaration to be an array with the strings `Naomi`, `Quincy,` and `CamperChan`. The order of values in an array is important, so follow that order. Remember that strings are case-sensitive.
# --hints--
The first element in your array should be the string `"Naomi"`.
```js
assert.equal(rows[0], "Naomi");
```
The second element in your array should be the string `"Quincy"`.
```js
assert.equal(rows[1], "Quincy");
```
The third element in your array should be the string `"CamperChan"`.
```js
assert.equal(rows[2], "CamperChan");
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
let character = 'Hello';
let count = 8;
let rows = [];
--fcc-editable-region--
```
@@ -0,0 +1,59 @@
---
id: 660f061d259bbebc37461080
title: Step 17
challengeType: 0
dashedName: step-17
---
# --description--
You can access the values inside an array using the <dfn>index</dfn> of the value. An index is a number representing the position of the value in the array, starting from `0` for the first value.
You can access the value using <dfn>bracket notation</dfn>, such as `array[0]`.
Use `console.log` and bracket notation to print the first value in your `rows` array.
# --hints--
You should have a `console.log()` statement in your code.
```js
assert.match(code, /console\.log/);
```
You should access your `rows` array.
```js
assert.lengthOf(code.match(/rows/g), 2);
```
You should use bracket notation with your `rows` array.
```js
assert.match(code, /rows\[/);
```
You should use bracket notation to access the first element of your `rows` array.
```js
assert.match(code, /rows\[\s*0\s*\]/);
```
You should log the first element of your `rows` array.
```js
assert.match(code, /console\.log\(\s*rows\[\s*0\s*]\s*\);?/);
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
let character = 'Hello';
let count = 8;
let rows = ["Naomi", "Quincy", "CamperChan"];
--fcc-editable-region--
```
@@ -0,0 +1,71 @@
---
id: 660f07d231941bc11719f664
title: Step 18
challengeType: 0
dashedName: step-18
---
# --description--
Arrays are special in that they are considered <dfn>mutable</dfn>. This means you can change the value at an index directly.
For example, this code would assign the number `25` to the second element in the array:
```js
let array = [1, 2, 3];
array[1] = 25;
```
Update the **third** element of your `rows` array to be the number `10`. Then print the `rows` array to your console.
# --hints--
You should use bracket notation on the `rows` array again.
```js
assert.lengthOf(code.match(/rows\[/g), 2)
```
You should access the third element of the `rows` array.
```js
assert.match(code, /rows\[\s*2\s*\]/);
```
You should use the assignment operator on the third element of the `rows` array.
```js
assert.match(code, /rows\[\s*2\s*\]\s*=/);
```
You should assign the value `10` to the third element of your `rows` array.
```js
assert.equal(rows[2], 10);
```
You should have a second `console.log` statement in your code.
```js
assert.lengthOf(code.match(/console\.log/g), 2);
```
You should log the `rows` array.
```js
assert.match(code, /console\.log\(\s*rows\s*\);?/);
```
# --seed--
## --seed-contents--
```js
let character = 'Hello';
let count = 8;
let rows = ["Naomi", "Quincy", "CamperChan"];
console.log(rows[0]);
--fcc-editable-region--
--fcc-editable-region--
```
@@ -0,0 +1,45 @@
---
id: 660f09a2694b59c3a10ee304
title: Step 20
challengeType: 0
dashedName: step-20
---
# --description--
For now, remove your first console log and your `rows[2]` assignment. Leave the second `rows` log statement for later.
# --hints--
You should remove your `console.log(rows[0])` statement.
```js
assert.notMatch(code, /console\.log\(\s*rows\[\s*0\s*\]\s*\)/);
```
You should remove your `rows[2]` reassignment.
```js
assert.notMatch(code, /rows\[2\]/);
```
You should not remove your `console.log(rows)` statement.
```js
assert.match(code, /console\.log\(\s*rows\s*\);/);
```
# --seed--
## --seed-contents--
```js
let character = 'Hello';
let count = 8;
let rows = ["Naomi", "Quincy", "CamperChan"];
--fcc-editable-region--
console.log(rows[0]);
rows[rows.length - 1] = 10;
--fcc-editable-region--
console.log(rows);
```
@@ -0,0 +1,52 @@
---
id: 660f0a55847d6cc485f29ba5
title: Step 21
challengeType: 0
dashedName: step-21
---
# --description--
A <dfn>method</dfn> in JavaScript is a function that's associated with certain values or objects. An example you've already encountered is the `.log()` method, which is part of the `console` object.
Arrays have their own methods, and the first you will explore is the `.push()` method. This allows you to "push" a value to the end of an array. Here is an example to add the number `12` to the end of an array:
```js
array.push(12);
```
Use `.push()` to add the string `"freeCodeCamp"` to the end of your `rows` array. Add this code before your `console.log` so you can see the change you made to your array.
# --hints--
You should use `.push()` in your code.
```js
assert.match(code, /\.push\(/);
```
You should use the `.push()` method of your `rows` array.
```js
assert.match(code, /rows\.push\(/);
```
You should pass the string `"freeCodeCamp"` to your `.push()` method.
```js
assert.match(code, /rows\.push\(\s*('|")freeCodeCamp\1\s*\);?/)
```
# --seed--
## --seed-contents--
```js
let character = 'Hello';
let count = 8;
--fcc-editable-region--
let rows = ["Naomi", "Quincy", "CamperChan"];
console.log(rows);
--fcc-editable-region--
```
@@ -0,0 +1,61 @@
---
id: 660f0c34aad72dc712b97624
title: Step 22
challengeType: 0
dashedName: step-22
---
# --description--
Another method essential for this project is the `.pop()` method. It removes the last element from an array and <dfn>returns</dfn> that element.
When a method returns a value, you can think of it as giving the value back to you, making it available for use in other parts of your code.
Declare a `popped` variable, and assign it the result of `rows.pop()`. Then, log your `popped` variable.
# --hints--
You should declare a `popped` variable.
```js
assert.match(code, /popped/);
```
You should use `let` to declare your `popped` variable.
```js
assert.match(code, /let\s+popped/);
```
You should call the `.pop()` method.
```js
assert.match(code, /\.pop\(\s*\)/);
```
You should call the `.pop()` method on your `rows` array.
```js
assert.match(code, /rows\.pop\(\s*\)/);
```
You should log your `popped` variable.
```js
assert.match(code, /console\.log\(\s*popped\s*\)/);
```
# --seed--
## --seed-contents--
```js
let character = 'Hello';
let count = 8;
--fcc-editable-region--
let rows = ["Naomi", "Quincy", "CamperChan"];
rows.push("freeCodeCamp");
console.log(rows);
--fcc-editable-region--
```
@@ -0,0 +1,55 @@
---
id: 660f0da9bf1035c9097af20a
title: Step 23
challengeType: 0
dashedName: step-23
---
# --description--
You should have seen `"freeCodeCamp"` printed to the console. This is because `.pop()` returns the value that was removed from the array - and you pushed `"freeCodeCamp"` to the end of the array earlier.
But what does `.push()` return? Assign your existing `rows.push()` to a new `pushed` variable, and log it.
# --hints--
You should declare a `pushed` variable.
```js
assert.match(code, /pushed/);
```
You should use `let` to declare your `pushed` variable.
```js
assert.match(code, /let\s+pushed/);
```
You should assign `rows.push("freeCodeCamp")` to your `pushed` variable.
```js
assert.equal(pushed, 4);
```
You should log your `pushed` variable.
```js
assert.match(code, /console\.log\(\s*pushed\s*\)/);
```
# --seed--
## --seed-contents--
```js
let character = 'Hello';
let count = 8;
let rows = ["Naomi", "Quincy", "CamperChan"];
--fcc-editable-region--
rows.push("freeCodeCamp");
--fcc-editable-region--
let popped = rows.pop();
console.log(popped);
console.log(rows);
```
@@ -0,0 +1,61 @@
---
id: 660f0ee51d7460ce88cd248d
title: Step 24
challengeType: 0
dashedName: step-24
---
# --description--
Were you expecting to see `4` in the console? `.push()` returns the new length of the array, after adding the value you give it.
It is important to be aware of what values a method returns. Take some time to experiment with `.push()` and `.pop()`. When you are ready, remove all of your `.push()` and `.pop()` calls, and your `console.log` statements.
# --hints--
You should not have a `.push()` call.
```js
assert.notMatch(code, /\.push\(/);
```
You should not have a `.pop()` call.
```js
assert.notMatch(code, /.pull\(/);
```
You should not have any log statements.
```js
assert.notMatch(code, /console\.log/);
```
You should not have a `popped` variable.
```js
assert.notMatch(code, /popped/);
```
You should not have a `pushed` variable.
```js
assert.notMatch(code, /pushed/);
```
# --seed--
## --seed-contents--
```js
let character = 'Hello';
let count = 8;
let rows = ["Naomi", "Quincy", "CamperChan"];
--fcc-editable-region--
let pushed = rows.push("freeCodeCamp");
console.log(pushed);
let popped = rows.pop();
console.log(popped);
console.log(rows);
--fcc-editable-region--
```
@@ -0,0 +1,38 @@
---
id: 660f0f980e98e8cf77f1ce31
title: Step 25
challengeType: 0
dashedName: step-25
---
# --description--
Change your `rows` declaration to be assigned an empty array again.
Also, change your `'Hello'` string to use double quotes again. Generally, it does not matter which of the two you prefer, but you will want to be consistent in that choice throughout your project.
# --hints--
Your `rows` array should be empty.
```js
assert.empty(rows);
```
Your `"Hello"` string should use double quotes.
```js
assert.match(code, /"Hello"/);
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
let character = 'Hello';
let count = 8;
let rows = ["Naomi", "Quincy", "CamperChan"];
--fcc-editable-region--
```
@@ -0,0 +1,65 @@
---
id: 660f165270622fd4ec0da3f7
title: Step 26
challengeType: 0
dashedName: step-26
---
# --description--
The `let` keyword allows a variable to be reassigned. This means you could change `character` later to be a completely different value.
For this project, you will not want to change these variable values. So instead, you should use `const` to declare them. `const` variables are special.
First, a `const` variable cannot be reassigned like a `let` variable. This code would throw an error:
```js
const firstName = "Naomi";
firstName = "Jessica";
```
A `const` variable also cannot be uninitialized. This code would throw an error:
```js
const firstName;
```
Replace your `let` keywords with `const`.
# --hints--
You should use `const` to declare your `character` variable.
```js
assert.match(code, /const\s+character/);
```
You should use `const` to declare your `count` variable.
```js
assert.match(code, /const\s+count/);
```
You should use `const` to declare your `rows` variable.
```js
assert.match(code, /const\s+rows/);
```
You should not use `let` in your code.
```js
assert.notMatch(code, /let/);
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
let character = "Hello";
let count = 8;
let rows = [];
--fcc-editable-region--
```
@@ -0,0 +1,32 @@
---
id: 660f17294346b7d69e79db3d
title: Step 27
challengeType: 0
dashedName: step-27
---
# --description--
You are now ready to start building your pyramid generator. Your `character` variable will serve as the building block for the pyramid.
`"Hello"` might not work very well for that. Change the value of `character` to be the hash character `"#"`.
# --hints--
Your `character` variable should be a hash symbol.
```js
assert.equal(character, "#");
```
# --seed--
## --seed-contents--
```js
--fcc-editable-region--
const character = "Hello";
const count = 8;
const rows = [];
--fcc-editable-region--
```
@@ -0,0 +1,67 @@
---
id: 660f17d4e9f227d86e834abd
title: Step 28
challengeType: 0
dashedName: step-28
---
# --description--
To generate a pyramid, you will need to create multiple rows. When you have to perform a task repeatedly until a condition is met, you will use a <dfn>loop</dfn>. There are many ways to write a loop.
You are going to start with a basic `for` loop. `for` loops use the following syntax:
```js
for (iterator; condition; iteration) {
logic;
}
```
In the upcoming steps, you'll explore each component of a loop in detail. For now, construct a `for` loop that includes the terms `"iterator"`, `"condition"`, and `"iteration"` for the three components. Keep the loop <dfn>body</dfn>, the section within the curly braces `{}`, empty.
# --hints--
You should have a `for` loop.
```js
assert.match(code, /for/);
```
The first component of your `for` loop should be the string `"iterator"`.
```js
assert.match(code, /for\s*\(\s*('|")iterator\1/);
```
The second component of your `for` loop should be the string `"condition"`.
```js
assert.match(code, /for\s*\(\s*('|")iterator\1\s*;\s*('|")condition\2/);
```
The third component of your `for` loop should be the string `"iteration"`.
```js
assert.match(code, /for\s*\(\s*('|")iterator\1\s*;\s*('|")condition\2\s*;\s*('|")iteration\3\s*\)/);
```
The body of your `for` loop should be empty.
```js
assert.match(code, /for\s*\(\s*('|")iterator\1\s*;\s*('|")condition\2\s*;\s*('|")iteration\3\s*\)\s*\{\s*\}/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
--fcc-editable-region--
```
@@ -0,0 +1,56 @@
---
id: 660f18f059fe0fda192ce394
title: Step 29
challengeType: 0
dashedName: step-29
---
# --description--
Your loop now needs a proper iterator. The <dfn>iterator</dfn> is a variable you can declare specifically in your `for` loop to control how the loop iterates or goes through your logic.
It is a common convention to use `i` as your iterator variable in a loop. A `for` loop allows you to declare this in the parentheses `()`. For example, here is a `for` loop that declares an `index` variable and assigns it the value `100`.
```js
for (let index = 100; "second"; "third") {
}
```
Replace the string `"iterator"` with a `let` declaration for the variable `i`. Assign it the value `0` to start. This will give the `i` variable the value `0` the **first time** your loop runs.
# --hints--
You should use `let` to declare an `i` variable.
```js
assert.match(code, /let\s+i/);
```
You should assign `0` to your `i` variable.
```js
assert.match(code, /let\s+i\s*=\s*0/);
```
Your `for` loop should start an `i` iterator at `0`.
```js
assert.match(code, /for\s*\(\s*let\s+i\s*=\s*0/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
for ("iterator"; "condition"; "iteration") {
}
--fcc-editable-region--
```
@@ -0,0 +1,52 @@
---
id: 660f1a00ac619ddc1e259a66
title: Step 30
challengeType: 0
dashedName: step-30
---
# --description--
The <dfn>condition</dfn> of a `for` loop tells the loop how many times it should iterate. When the `condition` becomes true, the loop will stop.
In JavaScript, a Boolean value can be either `true` or `false`. These are not strings - you will learn more about the difference later on.
For now, you will use the <dfn>less than</dfn> operator (`<`). This allows you to check if the value on the left is less than the value on the right. For example, `count < 3` would evaluate to `true` if `count` is `2`, and `false` if `count` is `4`.
Replace your `"condition"` string with a condition to check if `i` is less than `count`.
# --hints--
You should use the less than operator.
```js
assert.match(code, /</);
```
You should use the less than operator to check if `i` is less than `count`.
```js
assert.match(code, /i\s*<\s*count/);
```
Your `for` loop should use `i < count` as the condition.
```js
assert.match(code, /for\s*\(\s*let\s+i\s*=\s*0;\s*i\s*<\s*count;/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
for (let i = 0; "condition"; "iteration") {
}
--fcc-editable-region--
```
@@ -0,0 +1,50 @@
---
id: 660f1b6e60bd9edf902c81fd
title: Step 31
challengeType: 0
dashedName: step-31
---
# --description--
Your <dfn>iteration</dfn> statement will tell your loop what to do with the iterator after each run.
When you reassign a variable, you can use the variable to reference the previous value before the reassignment. This allows you to do things like add three to an existing number. For example, `bees = bees + 3;` would increase the value of `bees` by three.
Use that syntax to replace your `"iteration"` string with a reassignment statement that increases `i` by one.
# --hints--
You should add one to your `i` variable.
```js
assert.match(code, /i\s*\+\s*1/);
```
You should assign `i + 1` back to your `i` variable.
```js
assert.match(code, /i\s*=\s*i\s*\+\s*1/);
```
Your `for` loop should increase `i` by `1` on each iteration.
```js
assert.match(code, /for\s*\(\s*let\s+i\s*=\s*0;\s*i\s*<\s*count;\s*i\s*=\s*i\s*\+\s*1\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
for (let i = 0; i < count; "iteration") {
}
--fcc-editable-region--
```
@@ -0,0 +1,46 @@
---
id: 660f1bf673487ae0bb25b900
title: Step 32
challengeType: 0
dashedName: step-32
---
# --description--
Your loop should now run eight times. Inside the body of the loop, print the value of the `i` iterator and see what happens.
# --hints--
You should use `console.log()`.
```js
assert.match(code, /console\.log/)
```
You should log the value of `i`.
```js
assert.match(code, /console\.log\(\s*i\s*\)/);
```
You should log the value of `i` in your `for` loop.
```js
assert.match(code, /for\s*\(\s*let\s+i\s*=\s*0;\s*i\s*<\s*count;\s*i\s*=\s*i\s*\+\s*1\s*\)\s*\{\s*console\.log\(\s*i\s*\);?\s*\}/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
for (let i = 0; i < count; i = i + 1) {
}
--fcc-editable-region--
```
@@ -0,0 +1,54 @@
---
id: 660f1cedf3676fe26122ebf6
title: Step 33
challengeType: 0
dashedName: step-33
---
# --description--
You should see the numbers zero through seven printed in your console, one per line. This will serve as the foundation for generating your pyramid.
Replace your log statement with a statement to push `i` to your `rows` array.
# --hints--
You should not have a `console.log` call.
```js
assert.notMatch(code, /console/);
```
You should call `.push()` on your `rows` array.
```js
assert.match(code, /rows\.push\(/);
```
You should push `i` to your `rows` array.
```js
assert.match(code, /rows\.push\(\s*i\s*\)/);
```
Your `.push()` should happen in your `for` loop.
```js
assert.match(code, /for\s*\(\s*let\s+i\s*=\s*0;\s*i\s*<\s*count;\s*i\s*=\s*i\s*\+\s*1\s*\)\s*\{\s*rows\.push\(\s*i\s*\);?\s*\}/)
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
for (let i = 0; i < count; i = i + 1) {
console.log(i);
}
--fcc-editable-region--
```
@@ -0,0 +1,50 @@
---
id: 660f1e3f047bf4e403268713
title: Step 34
challengeType: 0
dashedName: step-34
---
# --description--
Unfortunately, now you cannot see what your loop is doing.
Use `let` to declare a `result` variable, and assign it an empty string. An empty string is represented by quotation marks with nothing between them, such as `""`.
# --hints--
You should declare a `result` variable.
```js
assert.match(code, /result/);
```
You should use `let` to declare your `result` variable.
```js
assert.match(code, /let\s*result/);
```
Your `result` variable should be an empty string.
```js
assert.equal(result, "");
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
for (let i = 0; i < count; i = i + 1) {
rows.push(i);
}
--fcc-editable-region--
--fcc-editable-region--
```
@@ -0,0 +1,44 @@
---
id: 660f20473aef47e9b8c9afc6
title: Step 35
challengeType: 0
dashedName: step-35
---
# --description--
Add a log statement to print the value of `result`. Depending on which console you use, you may not see anything printed.
# --hints--
You should add a `console.log` call.
```js
assert.match(code, /console\.log\(/);
```
You should log your `result` variable.
```js
assert.match(code, /console\.log\(\s*result\s*\);?/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
for (let i = 0; i < count; i = i + 1) {
rows.push(i);
}
let result = ""
--fcc-editable-region--
--fcc-editable-region--
```
@@ -0,0 +1,82 @@
---
id: 660f207334fabaeac3269c38
title: Step 36
challengeType: 0
dashedName: step-36
---
# --description--
To manipulate the `result` string, you will use a different type of loop. Specifically, a `for...of` loop, which iterates over each item in an iterable object and temporarily assigns it to a variable.
The syntax for a `for...of` loop looks like:
```js
for (const value of iterable) {
}
```
Note that you can use `const` because the variable only exists for a single iteration, not during the entire loop.
Create a `for...of` loop to iterate through your `rows` array, assigning each value to a `row` variable.
# --hints--
You should use another `for` keyword.
```js
assert.lengthOf(code.match(/for/g), 2);
```
You should declare a `row` variable.
```js
assert.match(code, /\s+row\s+/);
```
You should use `const` to declare your `row` variable.
```js
assert.match(code, /const\s+row\s+/);
```
Your `for...of` loop should declare your `row` variable.
```js
assert.match(code, /for\s*\(\s*const\s+row\s+/);
```
Your `row` variable should be extracted from `rows` using the `of` keyword.
```js
assert.match(code, /for\s*\(\s*const\s+row\s+of\s+rows\s*\)/);
```
Your `for...of` loop body should be empty.
```js
assert.match(code, /for\s*\(\s*const\s+row\s+of\s+rows\s*\)\s*\{\s*\}/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
for (let i = 0; i < count; i = i + 1) {
rows.push(i);
}
let result = ""
--fcc-editable-region--
--fcc-editable-region--
console.log(result);
```
@@ -0,0 +1,58 @@
---
id: 660f229d2dbe09ef2954a4a1
title: Step 37
challengeType: 0
dashedName: step-37
---
# --description--
Remember in your previous loop that you used the addition operator `+` to increase the value of `i` by `1`.
You can do a similar thing with a string value, by appending a new string to an existing string. For example, `hello = hello + " World";` would add the string `" World"` to the existing string stored in the `hello` variable. This is called <dfn>concatenation</dfn>.
In your `for...of` loop, use the addition operator to concatenate the `row` value to the `result` value.
# --hints--
You should use the concatenation operator on your `result` variable.
```js
assert.match(code, /result\s*\+/);
```
You should concatenate `row` to your `result` variable.
```js
assert.match(code, /result\s*\+\s*row/);
```
You should assign the result of your concatenation back to the `result` variable.
```js
assert.match(code, /result\s*=\s*result\s*\+\s*row;?/)
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
for (let i = 0; i < count; i = i + 1) {
rows.push(i);
}
let result = ""
--fcc-editable-region--
for (const row of rows) {
}
--fcc-editable-region--
console.log(result);
```
@@ -0,0 +1,68 @@
---
id: 660f23b53db70af0f2620e78
title: Step 38
challengeType: 0
dashedName: step-38
---
# --description--
Now all of your numbers are appearing on the same line. This will not work for creating a pyramid.
You will need to add a new line to each row. However, pressing the return key to insert a line break between quotes in JavaScript will result in a parsing error. Instead, you need to use the special <dfn>escape sequence</dfn> `\n`, which is interpreted as a new line when the string is logged. For example:
```js
lineOne = lineOne + "\n" + lineTwo;
```
Use a second addition operator to concatenate a new line between the existing `result` value and the added `row` value.
# --hints--
You should use the `\n` escape sequence. Remember that it needs to be a string, so it is wrapped in quotes.
```js
assert.match(code, /('|")\\n\1/);
```
You should concatenate the `\n` escape sequence to your `result` variable.
```js
assert.match(code, /result\s*\+\s*('|")\\n\1/);
```
You should concatenate your `row` variable to your `\n` escape sequence.
```js
assert.match(code, /result\s*\+\s*('|")\\n\1\s*\+\s*row/);
```
You should assign the entire concatenation back to your `result` variable. Don't forget your semi-colon.
```js
assert.match(code, /result\s*=\s*result\s*\+\s*('|")\\n\1\s*\+\s*row;/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
for (let i = 0; i < count; i = i + 1) {
rows.push(i);
}
let result = ""
--fcc-editable-region--
for (const row of rows) {
result = result + row;
}
--fcc-editable-region--
console.log(result);
```
@@ -0,0 +1,50 @@
---
id: 660f255022991ef34ed0ee88
title: Step 39
challengeType: 0
dashedName: step-39
---
# --description--
Printing numbers won't result in a visually appealing pyramid. Now that you're outputting the formatted content of your `rows` array, it's time to update your original loop.
Instead of pushing `i` to the array, push the value of your `character` variable.
# --hints--
You should no longer push your `i` variable.
```js
assert.notMatch(code, /rows\.push\(\s*i\s*\)/);
```
You should push your `character` variable.
```js
assert.match(code, /rows\.push\(\s*character\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
for (let i = 0; i < count; i = i + 1) {
rows.push(i);
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,63 @@
---
id: 660f280dda5040f707c76b4a
title: Step 40
challengeType: 0
dashedName: step-40
---
# --description--
Now you have a series of `#` characters, but the pyramid shape is still missing. Fortunately, the `i` variable represents the current "row" number in your loop, enabling you to use it for crafting a pyramid-like structure.
To achieve this, you will use the `.repeat()` method available to strings. This method accepts a number as an argument, specifying the number of times to repeat the target string. For example, using `.repeat()` to generate the string `"Code! Code! Code!"`:
```js
const activity = "Code! ";
activity.repeat(3);
```
Use the `.repeat()` method on your `character`, and give it `i` for the number.
# --hints--
You should use the `.repeat()` method.
```js
assert.match(code, /\.repeat\(/);
```
You should use the `.repeat()` method on your `character` variable.
```js
assert.match(code, /character\.repeat\(/);
```
You should pass `i` to your `.repeat()` method.
```js
assert.match(code, /character\.repeat\(\s*i\s*\)/)
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
for (let i = 0; i < count; i = i + 1) {
rows.push(character);
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,46 @@
---
id: 660f2a70ad6225fa503e71c3
title: Step 41
challengeType: 0
dashedName: step-41
---
# --description--
You're getting closer! At this point, you're encountering what's known as an <dfn>off-by-one error</dfn>, a frequent problem in zero-based indexing languages like JavaScript.
The first index of your `rows` array is `0`, which is why you start your `for` loop with `i = 0`. But repeating a string zero times results in nothing to print.
To fix this, add `1` to the value of `i` in your `.repeat()` call. Do not assign it back to `i` like you did in your loop conditions.
# --hints--
You should add `1` to `i` in your `.repeat()` method.
```js
assert.match(code, /character\.repeat\(\s*i\s*\+\s*1\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
for (let i = 0; i < count; i = i + 1) {
rows.push(character.repeat(i))
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,75 @@
---
id: 660f2b6fd54ac1fc142804dd
title: Step 42
challengeType: 0
dashedName: step-42
---
# --description--
The logic for formatting this pyramid is likely going to get complicated, which means it's a great time to extract that code into a function.
A <dfn>function</dfn> is a block of code that can be reused throughout your application. Functions are declared with the following syntax:
```js
function name(parameter) {
}
```
The `function` keyword tells JavaScript that the `name` variable is going to be a function. `parameter` is a variable that represents a value that is passed into the function when it is used. A function may have as many, or as few, <dfn>parameters</dfn> as you'd like. Like a `for` loop, the space between the curly braces is the <dfn>function body</dfn>.
Declare a `padRow` function. Do not create any parameter variables yet. The function body should be empty. Remember that you need to use camel case for your naming convention.
# --hints--
You should use the `function` keyword.
```js
assert.match(code, /function/);
```
You should declare a `padRow` function.
```js
assert.isFunction(padRow);
```
Your `padRow()` function should not have any parameters.
```js
assert.match(code, /padRow\s*\(\s*\)/);
```
Your `padRow()` function should have an empty body.
```js
assert.match(code, /padRow\s*\(\s*\)\s*\{\s*\}/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
--fcc-editable-region--
for (let i = 0; i < count; i = i + 1) {
rows.push(character.repeat(i + 1))
}
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,67 @@
---
id: 660f2eccfe3f820304af1b39
title: Step 57
challengeType: 0
dashedName: step-57
---
# --description--
In order to know how to format a row, your `padRow` function will need to know which row number you are on, and how many rows in total are being generated.
The best way to do this is by creating function parameters for them. Give your `padRow` function a `rowNumber` and `rowCount` parameter. Multiple parameters are separated by a comma:
```js
function name(first, second) {
}
```
# --hints--
Your `padRow` function should have a `rowNumber` parameter.
```js
assert.match(code, /function\s+padRow\s*\(\s*rowNumber/);
```
You should add a comma after your `rowNumber` parameter.
```js
assert.match(code, /function\s+padRow\s*\(\s*rowNumber\s*,\s*/);
```
Your `padRow` function should have a `rowCount` parameter.
```js
assert.match(code, /function\s+padRow\s*\(\s*rowNumber\s*,\s*rowCount\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
function padRow() {
}
--fcc-editable-region--
for (let i = 0; i < count; i = i + 1) {
rows.push(character.repeat(i + 1))
}
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,81 @@
---
id: 660f2fbd45b520046cac68e8
title: Step 58
challengeType: 0
dashedName: step-58
---
# --description--
Remember in an earlier step, you learned about return values. A function can <dfn>return</dfn> a value for your application to consume separately.
In a function, the `return` keyword is used to specify a return value. For example, this function would return the value given to the first parameter:
```js
function name(parameter) {
return parameter;
}
```
Use the `return` keyword to return the value of the `character` variable, repeated `rowNumber` times.
# --hints--
You should use the `.repeat()` method.
```js
assert.lengthOf(code.match(/\.repeat\(/g), 2);
```
You should use the `.repeat()` method on your `character` variable.
```js
assert.lengthOf(code.match(/character\.repeat\(/g), 2);
```
You should pass `rowNumber` to your `.repeat()` call.
```js
assert.match(code, /character\.repeat\(\s*rowNumber\s*\)/);
```
You should use the `return` keyword.
```js
assert.match(code, /return/);
```
You should return the result of your `.repeat()` call.
```js
assert.equal(padRow(3), "###");
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
function padRow(rowNumber, rowCount) {
}
--fcc-editable-region--
for (let i = 0; i < count; i = i + 1) {
rows.push(character.repeat(i + 1))
}
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,67 @@
---
id: 660f34626216270c682e2f7b
title: Step 59
challengeType: 0
dashedName: step-59
---
# --description--
A <dfn>function call</dfn> allows you to actually use a function. You may not have been aware of it, but the methods like `.push()` that you have been using have been function calls.
A function is called by referencing the function's name, and adding `()`. Here's how to call a `test` function:
```js
test();
```
Replace the `character.repeat(i + 1)` in your `.push()` call with a function call for your `padRow` function.
# --hints--
You should not use `i + 1` in your `push` call.
```js
assert.notMatch(code, /repeat\(\s*i\s*\+\s*1\s*\)/);
```
You should not use `character.repeat` in your `.push()` call.
```js
assert.notMatch(code, /push\(\s*character/);
```
You should call `padRow` in your `.push()` call.
```js
assert.match(code, /push\(\s*padRow\(\s*\)\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return character.repeat(rowNumber);
}
--fcc-editable-region--
for (let i = 0; i < count; i = i + 1) {
rows.push(character.repeat(i + 1))
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,67 @@
---
id: 660f34e99571070d56d2f231
title: Step 60
challengeType: 0
dashedName: step-60
---
# --description--
Your `padRow` function has two parameters which you defined. Values are provided to those parameters when a function is called.
The values you provide to a function call are referred to as <dfn>arguments</dfn>, and you <dfn>pass</dfn> arguments to a function call. Here's a function call with `"Hello"` passed as an argument:
```js
test("Hello");
```
Pass `i + 1` and `count` as the arguments to your `padRow` call. Like parameters, arguments are separated by a comma.
# --hints--
You should pass `i + 1` to your `padRow()` call.
```js
assert.match(code, /push\(\s*padRow\(\s*i\s*\+\s*1/);
```
You should have a comma after your `i + 1` argument.
```js
assert.match(code, /push\(\s*padRow\(\s*i\s*\+\s*1\s*,\s*/);
```
You should pass `count` as your second argument.
```js
assert.match(code, /push\(\s*padRow\(\s*i\s*\+\s*1\s*,\s*count\s*\)\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return character.repeat(rowNumber);
}
--fcc-editable-region--
for (let i = 0; i < count; i = i + 1) {
rows.push(padRow())
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,60 @@
---
id: 660f359af3e32e0f1a6880b7
title: Step 61
challengeType: 0
dashedName: step-61
---
# --description--
You should now see the same bunch of characters in your console. Your `padRow` function is doing the exact same thing you were doing earlier, but now it's in a reusable section of its own.
Use the addition operator to concatenate a blank space `" "` to the beginning and end of your repeated `character` string.
# --hints--
You should concatenate an empty space to the beginning of your returned value.
```js
assert.match(padRow(1, 1), /^\s/);
```
You should concatenate an empty space to the end of your returned value.
```js
assert.match(padRow(1, 1), /\s$/);
```
Your `padRow()` function should return the repeated `character` series with a space before and after the series.
```js
assert.equal(padRow(1, 1), " # ");
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
function padRow(rowNumber, rowCount) {
return character.repeat(rowNumber);
}
--fcc-editable-region--
for (let i = 0; i < count; i = i + 1) {
rows.push(padRow(i + 1, count));
}
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,64 @@
---
id: 660f374d532dc41189cc9cc2
title: Step 62
challengeType: 0
dashedName: step-62
---
# --description--
Now it is time for a bit of math. Consider a three-row pyramid. If we want it centered, it would look something like:
```md
··#··
·###·
#####
```
Empty spaces have been replaced with interpuncts, or middle dots, for readability. If you extrapolate the pattern, you can see that the spaces at the beginning and end of a row follow a pattern.
Update your blank space strings to be repeated `rowCount - rowNumber` times.
Open up the console to see the result.
# --hints--
You should call `.repeat()` on your two `" "` strings.
```js
assert.lengthOf(code.match(/" ".repeat/g), 2);
```
Your `" "` strings should be repeated `rowCount - rowNumber` times.
```js
assert.equal(padRow(1, 3), " # ");
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
function padRow(rowNumber, rowCount) {
return " " + character.repeat(rowNumber) + " ";
}
--fcc-editable-region--
for (let i = 0; i < count; i = i + 1) {
rows.push(padRow(i + 1, count));
}
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,63 @@
---
id: 660f383d4c772c12ff59904b
title: Step 63
challengeType: 0
dashedName: step-63
---
# --description--
You can pass full expressions as an argument. The function will receive the result of evaluating that expression. For example, these two function calls would yield the same result:
```js
test(2 * 3 + 1);
test(7);
```
Looking at the pattern again:
```md
··#··
·###·
#####
```
Update the `character` value to be repeated `2 * rowNumber - 1` times.
Open up the console again to see the updated result.
# --hints--
Your function should pass `2 * rowNumber - 1` to your `.repeat()` call.
```js
assert.equal(padRow(4, 5), " ####### ");
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(rowNumber) + " ".repeat(rowCount - rowNumber);
}
--fcc-editable-region--
for (let i = 0; i < count; i = i + 1) {
rows.push(padRow(i + 1, count));
}
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,61 @@
---
id: 660f38c34a4de6141c0c369f
title: Step 64
challengeType: 0
dashedName: step-64
---
# --description--
Your pyramid generator now functions as expected. But this is an excellent opportunity to further explore the code you have written.
The addition operator is not the only way to add values to a variable. The <dfn>addition assignment</dfn> operator can be used as shorthand to mean "take the original value of the variable, add this value, and assign the result back to the variable." For example, these two statements would yield the same result:
```js
test = test + 1;
test += 1;
```
Update your iterator statement in the `for` loop to use addition assignment.
# --hints--
Your `for` loop should not use `i = i + 1`;
```js
assert.notMatch(code, /i\s*=\s*i\s*\+\s*1/);
```
Your `for` loop should use addition assignment with `i`.
```js
assert.match(code, /i\s*\+=\s*1/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
--fcc-editable-region--
for (let i = 0; i < count; i = i + 1) {
--fcc-editable-region--
rows.push(padRow(i + 1, count));
}
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,59 @@
---
id: 660f3915b41a441537ec9f5e
title: Step 65
challengeType: 0
dashedName: step-65
---
# --description--
Because you are only increasing `i` by `1`, you can use the <dfn>increment operator</dfn> `++`. This operator increases the value of a variable by 1, updating the assignment for that variable. For example, `test` would become `8` here:
```js
let test = 7;
test++;
```
Replace your addition assignment with the increment operator for your loop iteration.
# --hints--
Your `for` loop should not use addition assignment with `i`.
```js
assert.notMatch(code, /i\s*\+=\s*1/);
```
Your `for` loop should use the increment operator on `i`.
```js
assert.match(code, /i\s*\+\+/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
--fcc-editable-region--
for (let i = 0; i < count; i += 1) {
--fcc-editable-region--
rows.push(padRow(i + 1, count));
}
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,48 @@
---
id: 660f39b444fd6f16d1e49c1f
title: Step 66
challengeType: 0
dashedName: step-66
---
# --description--
Rather than having to pass `i + 1` to your `padRow` call, you could instead start your loop at `1`. This would allow you to create a one-indexed loop.
Update your iterator to start at `1` instead of `0`.
# --hints--
Your `for` loop should initialise `i` at `1`.
```js
assert.match(code, /for\s*\(\s*let\s+i\s*=\s*1/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
--fcc-editable-region--
for (let i = 0; i < count; i++) {
rows.push(padRow(i + 1, count));
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,54 @@
---
id: 660f3b664421471aa595170f
title: Step 67
challengeType: 0
dashedName: step-67
---
# --description--
The pyramid looks a little funny now. Because you are starting the loop at `1` instead of `0`, you do not need to add one to `i` when you pass it to `padRow`.
Update the first argument of your `padRow` call to be `i`.
# --hints--
You should not pass `i + 1` to `padRow`.
```js
assert.notMatch(code, /padRow\(\s*i\s*\+\s*1/);
```
You should pass `i` to `padRow`.
```js
assert.match(code, /padRow\(\s*i\s*,/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
--fcc-editable-region--
for (let i = 1; i < count; i++) {
rows.push(padRow(i + 1, count));
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,58 @@
---
id: 660f3ba3cceef11b6ba08b59
title: Step 68
challengeType: 0
dashedName: step-68
---
# --description--
Unfortunately, now the bottom of the pyramid has disappeared. This is because you have created another <dfn>off-by-one error</dfn>.
Your original loop went for `i` values from `0` to `7`, because `count` is `8` and your condition requires `i` to be less than `count`. Your loop is now running for `i` values from `1` to `7`.
Your loop needs to be updated to run when `i` is `8`, too. Looking at your logic, this means your loop should run when `i` is <dfn>less than or equal to</dfn> `count`. You can use the less than or equal to operator `<=` for this.
Update your loop condition to run while `i` is less than or equal to `count`.
# --hints--
Your `for` loop should not check if `i` is less than `count`.
```js
assert.notMatch(code, /i\s*<\s*count/);
```
Your `for` loop should check if `i` is less than or equal to `count`.
```js
assert.match(code, /i\s*<=\s*count/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
--fcc-editable-region--
for (let i = 1; i < count; i++) {
rows.push(padRow(i, count));
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,57 @@
---
id: 660f3ce51f70571e1c5227c8
title: Step 69
challengeType: 0
dashedName: step-69
---
# --description--
Comments can be helpful for explaining why your code takes a certain approach, or leaving to-do notes for your future self.
In JavaScript, you can use `//` to leave a single-line comment in your code.
Add a single-line comment above your function to remind yourself to change the code to a different kind of loop.
# --hints--
You should start a single-line comment with `//`.
```js
assert.match(code, /\/\//);
```
Your single-line comment should be at least five characters long.
```js
assert.match(code, /\/\/.{5,}/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
--fcc-editable-region--
for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,66 @@
---
id: 660f3dd626be3a1ffe27e5d1
title: Step 70
challengeType: 0
dashedName: step-70
---
# --description--
JavaScript also has support for multi-line comments. A multi-line comment starts with `/*` and ends with `*/`.
Unlike a single-line comment, a multi-line comment will encapsulate multiple lines.
Use `/*` and `*/` to turn your current `for` loop, including the body, into a multi-line comment.
# --hints--
You should start a multi-line comment with `/*`.
```js
assert.match(code, /\/\*/);
```
You should end a multi-line comment with `*/`.
```js
assert.match(code, /\*\//);
```
Your entire `for` loop should be commented out.
```js
const stripped = __helpers.removeJSComments(code);
assert.lengthOf(stripped.match(/for/g), 1);
assert.notMatch(stripped, /rows\.push/);
assert.notMatch(stripped, /i <= count/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
--fcc-editable-region--
for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,71 @@
---
id: 660f415b76859a2736771607
title: Step 71
challengeType: 0
dashedName: step-71
---
# --description--
Your pyramid has disappeared again. That's okay - that is to be expected.
Before you create your new loop, you need to learn about `if` statements. An <dfn>`if` statement</dfn> allows you to run a block of code only when a condition is met. They use the following syntax:
```js
if (condition) {
logic
}
```
Create an `if` statement with the boolean `true` as the condition. In the body, print the string `"Condition is true"`.
# --hints--
You should create an `if` statement.
```js
assert.match(code, /if/);
```
Your `if` statement should have `true` as the condition.
```js
assert.match(code, /if\s*\(\s*true\s*\)/);
```
Your `if` body should log `"Condition is true"`.
```js
assert.match(code, /if\s*\(\s*true\s*\)\s*\{\s*console\.log\(\s*("|')Condition is true\1\s*\);?/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
--fcc-editable-region--
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,53 @@
---
id: 660f4377a359972c521d3f4b
title: Step 72
challengeType: 0
dashedName: step-72
---
# --description--
You'll see the string printed in the console, because `true` is in fact true.
Change the condition of your `if` statement to the boolean `false`.
# --hints--
Your `if` condition should have `false` as the condition.
```js
assert.match(code, /if\s*\(\s*false\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
--fcc-editable-region--
if (true) {
console.log("Condition is true");
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,53 @@
---
id: 660f4455f457ef2e3ec6920f
title: Step 73
challengeType: 0
dashedName: step-73
---
# --description--
Now the string is no longer printing, because `false` is not `true`. But what about other values?
Try changing the condition to the string `"false"`.
# --hints--
Your `if` statement should have the string `"false"` as the condition.
```js
assert.match(code, /if\s*\(\s*('|")false\1\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
--fcc-editable-region--
if (false) {
console.log("Condition is true");
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,57 @@
---
id: 660f447efc0e722f016c1be0
title: Step 74
challengeType: 0
dashedName: step-74
---
# --description--
The text has appeared again! This is because `"false"` is a string, which when evaluated to a boolean becomes `true`. This means `"false"` is a truthy value.
A <dfn>truthy value</dfn> is a value that is considered true when evaluated as a boolean. Most of the values you encounter in JavaScript will be truthy.
A <dfn>falsy value</dfn> is the opposite - a value considered false when evaluated as a boolean. JavaScript has a defined list of falsy values. Some of them include `false`, `0`, `""`, `null`, `undefined`, and `NaN`.
Try changing your `if` condition to an empty string `""`, which is a falsy value.
# --hints--
Your `if` statement should have `""` as the condition.
```js
assert.match(code, /if\s*\(\s*("|')\1\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
--fcc-editable-region--
if ("false") {
console.log("Condition is true");
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,77 @@
---
id: 660f44f10ea40f300b896a5e
title: Step 75
challengeType: 0
dashedName: step-75
---
# --description--
The text is gone again! Empty strings evaluate to `false`, making them a <dfn>falsy value</dfn>. You will learn more about truthy and falsy values in future projects.
For now, remove your `if` statement entirely. Use `let` to declare a `continueLoop` variable and assign it the boolean `false`. Then use `let` to declare a `done` variable and assign it the value `0`.
# --hints--
You should not have an `if` statement.
```js
assert.notMatch(code, /if\s*\(/);
```
You should use `let` to declare a `continueLoop` variable.
```js
assert.match(code, /let\s+continueLoop/);
```
Your `continueLoop` variable should have the value `false`.
```js
assert.isFalse(continueLoop);
```
You should use `let` to declare a `done` variable.
```js
assert.match(code, /let\s+done/);
```
Your `done` variable should have the value `0`.
```js
assert.equal(done, 0);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
--fcc-editable-region--
if ("") {
console.log("Condition is true");
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,65 @@
---
id: 660f455b044d3230ed971e98
title: Step 76
challengeType: 0
dashedName: step-76
---
# --description--
A <dfn>`while`</dfn> loop will run over and over again until the `condition` specified is no longer true. It has the following syntax:
```js
while (condition) {
logic;
}
```
Use that syntax to declare a `while` loop with `continueLoop` as the condition. The body should be empty.
# --hints--
You should use a `while` loop.
```js
assert.match(code, /while/);
```
Your `while` loop should use `continueLoop` as the condition.
```js
assert.match(code, /while\s*\(\s*continueLoop\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
--fcc-editable-region--
let continueLoop = false;
let done = 0;
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,56 @@
---
id: 660f45ccf4ca5c31f253005a
title: Step 77
challengeType: 0
dashedName: step-77
---
# --description--
Right now, if you change `continueLoop` to true, your `while` loop will run forever. This is called an <dfn>infinite loop</dfn>, and you should be careful to avoid these. An infinite loop can lock up your system, requiring a full restart to escape.
To avoid this, start by using the increment operator to increase the value of the `done` variable inside your loop.
# --hints--
Your `while` loop should increment the `done` variable.
```js
assert.match(code, /while\s*\(\s*continueLoop\s*\)\s*\{\s*done\+\+/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
let continueLoop = false;
let done = 0;
--fcc-editable-region--
while (continueLoop) {
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,61 @@
---
id: 660f46460f9c36330ebc07d8
title: Step 79
challengeType: 0
dashedName: step-79
---
# --description--
The equality operator can lead to some strange behavior in JavaScript. For example, `"0" == 0` is true, even though one is a string and one is a number.
The <dfn>strict equality</dfn> operator `===` is used to check if two values are equal and share the same type. As a general rule, this is the equality operator you should always use. With the strict equality operator, `"0" === 0` becomes false, because while they might have the same value of zero, they are not of the same type.
Update your `done == count` condition to use the strict equality operator.
# --hints--
Your `if` condition should use strict equality.
```js
assert.match(code, /while\s*\(\s*continueLoop\s*\)\s*\{\s*done\+\+;\s*if\s*\(\s*(?:done\s*===\s*count|count\s*===\s*done)\s*\)\s*\{/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
let continueLoop = false;
let done = 0;
while (continueLoop) {
done++;
--fcc-editable-region--
if (done == count) {
}
--fcc-editable-region--
}
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,59 @@
---
id: 660f46b9c417a8341729a3ab
title: Step 80
challengeType: 0
dashedName: step-80
---
# --description--
When `done` has reached the value of `count`, we want the loop to stop executing.
Inside your `if` body, assign the boolean `false` to your `continueLoop` variable.
# --hints--
Your `if` body should assign `false` to your `continueLoop` variable.
```js
assert.match(code, /while\s*\(\s*continueLoop\s*\)\s*\{\s*done\+\+;\s*if\s*\(\s*(?:done\s*===\s*count|count\s*===\s*done)\s*\)\s*\{\s*continueLoop\s*=\s*false;?/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
let continueLoop = false;
let done = 0;
while (continueLoop) {
done++;
--fcc-editable-region--
if (done === count) {
}
--fcc-editable-region--
}
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,76 @@
---
id: 660f4774e3e0df35a68bb5f2
title: Step 81
challengeType: 0
dashedName: step-81
---
# --description--
To make your pyramid generate again, push the result of calling `padRow` with `done` and `count` as the arguments to your `rows` array, similar to what you did in your first loop.
# --hints--
Your loop should call the `.push()` method on your `rows`.
```js
assert.match(code, /while\s*\(\s*continueLoop\s*\)\s*\{\s*done\+\+;\s*rows\.push\(/);
```
You should call your `padRow` function in your `.push()` method.
```js
assert.match(code, /while\s*\(\s*continueLoop\s*\)\s*\{\s*done\+\+;\s*rows\.push\(\s*padRow\(/);
```
You should pass `done` as the first argument to your `padRow` call.
```js
assert.match(code, /while\s*\(\s*continueLoop\s*\)\s*\{\s*done\+\+;\s*rows\.push\(\s*padRow\(\s*done/);
```
You should pass `count` as the second argument to your `padRow` call.
```js
assert.match(code, /while\s*\(\s*continueLoop\s*\)\s*\{\s*done\+\+;\s*rows\.push\(\s*padRow\(\s*done\s*,\s*count\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
let continueLoop = false;
let done = 0;
while (continueLoop) {
done++;
--fcc-editable-region--
--fcc-editable-region--
if (done === count) {
continueLoop = false;
}
}
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,60 @@
---
id: 660f47afe4c98536715d5fa4
title: Step 82
challengeType: 0
dashedName: step-82
---
# --description--
The <dfn>strict inequality</dfn> operator `!==` allows you to check if two values are not equal, or do not have the same type. The syntax is similar to the equality operator: `value !== 4`.
Update your `while` loop condition to check if `done` is not equal to `count`.
# --hints--
Your `while` loop should check if `done` and `count` are not equal.
```js
assert.match(code, /while\s*\(\s*(?:done\s*!==\s*count|count\s*!==\s*done)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
let continueLoop = false;
let done = 0;
--fcc-editable-region--
while (continueLoop) {
done++;
rows.push(padRow(done, count));
if (done === count) {
continueLoop = false;
}
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,64 @@
---
id: 660f487dc0c8fa38084f9754
title: Step 83
challengeType: 0
dashedName: step-83
---
# --description--
Since you have moved the comparison into the `while` condition, you can remove your entire `if` statement.
# --hints--
You should no longer have an `if` statement.
```js
assert.notMatch(code, /if\s*\(\s*done\)/);
```
You should no longer set `continueLoop` to `false`.
```js
assert.lengthOf(code.match(/continueLoop\s*=\s*false/g), 1);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
let continueLoop = false;
let done = 0;
--fcc-editable-region--
while (done !== count) {
done++;
rows.push(padRow(done, count));
if (done === count) {
continueLoop = false;
}
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,57 @@
---
id: 660f48a419b40238e2b8b4d5
title: Step 84
challengeType: 0
dashedName: step-84
---
# --description--
Your loop is no longer relying on the `continueLoop` variable. This makes the variable an <dfn>unused declaration</dfn>. Generally, you want to avoid unused declarations to prevent future confusion.
Remove your `continueLoop` variable.
# --hints--
You should no longer have a `continueLoop` variable.
```js
assert.notMatch(code, /continueLoop/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
--fcc-editable-region--
let continueLoop = false;
let done = 0;
while (done !== count) {
done++;
rows.push(padRow(done, count));
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,58 @@
---
id: 660f48e1d3682f39e81843c4
title: Step 85
challengeType: 0
dashedName: step-85
---
# --description--
Your pyramid generator is still working. However, it could be possible to end up with an infinite loop again.
Because you are only checking if `done` is not equal to `count`, if `done` were to be **larger** than `count` your loop would go on forever.
Update your loop's condition to check if `done` is less than or equal to `count`.
# --hints--
Your `while` loop should check if `done` is less than or equal to `count`.
```js
assert.match(code, /while\s*\(\s*done\s*<=\s*count\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
--fcc-editable-region--
let done = 0;
while (done !== count) {
done++;
rows.push(padRow(done, count));
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,58 @@
---
id: 660f4934fb48f63abd5ae371
title: Step 86
challengeType: 0
dashedName: step-86
---
# --description--
Using `done` to track the number of rows that have been generated is functional, but you can actually clean up the logic a bit further.
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`.
# --hints--
Your `while` loop should check if `rows.length` is less than or equal to `count`.
```js
assert.match(code, /while\s*\(\s*rows\.length\s*<=\s*count\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
--fcc-editable-region--
let done = 0;
while (done <= count) {
done++;
rows.push(padRow(done, count));
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,60 @@
---
id: 660f4990b1caa03b9dc97a43
title: Step 88
challengeType: 0
dashedName: step-88
---
# --description--
Now you no longer need your `done` variable. Remove the increment operation from your loop, and the variable declaration for `done`.
# --hints--
You should not increment the `done` variable.
```js
assert.notMatch(code, /done\+\+/);
```
You should no longer have a `done` variable.
```js
assert.notMatch(code, /done/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
--fcc-editable-region--
let done = 0;
while (rows.length < count) {
done++;
rows.push(padRow(rows.length + 1, count));
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,61 @@
---
id: 660f49e32001983c90b75850
title: Step 89
challengeType: 0
dashedName: step-89
---
# --description--
That's a very clean and functional loop. Nice work! But there's still more to explore.
Use a multi-line comment to comment out your `while` loop.
# --hints--
Your `while` loop should be commented out.
```js
const stripped = __helpers.removeJSComments(code);
assert.notMatch(stripped, /while/);
```
Your `while` loop body should be commented out.
```js
const stripped = __helpers.removeJSComments(code);
assert.notMatch(stripped, /rows\.push/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
--fcc-editable-region--
while (rows.length < count) {
rows.push(padRow(rows.length + 1, count));
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,75 @@
---
id: 660f4a1472f8e63d76162ce5
title: Step 90
challengeType: 0
dashedName: step-90
---
# --description--
What if you made your pyramid upside-down, or <dfn>inverted</dfn>? Time to try it out!
Start by creating a new `for` loop. Declare your iterator `i` and assign it the value of `count`, then use the boolean `false` for your condition and iteration statements.
# --hints--
Your code should have a `for` loop.
```js
const stripped = __helpers.removeJSComments(code);
assert.match(stripped, /for\s*\(/);
```
Your `for` loop should initialise `i` with the value of `count`.
```js
assert.match(code, /for\s*\(\s*let\s*i\s*=\s*count/);
```
Your `for` loop should use `false` as the condition.
```js
assert.match(code, /for\s*\(\s*let\s*i\s*=\s*count\s*;\s*false/);
```
Your `for` loop should use `false` as the iteration.
```js
assert.match(code, /for\s*\(\s*let\s*i\s*=\s*count\s*;\s*false\s*;\s*false\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
/*while (rows.length < count) {
rows.push(padRow(rows.length + 1, count));
}*/
--fcc-editable-region--
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,57 @@
---
id: 660f4a83373de83ea101685f
title: Step 91
challengeType: 0
dashedName: step-91
---
# --description--
Because you are going to loop in the opposite direction, your loop needs to run while `i` is greater than `0`. You can use the <dfn>greater than</dfn> operator `>` for this.
Set your loop's condition to run when `i` is greater than `0`.
# --hints--
Your `for` loop should run when `i` is greater than `0`.
```js
assert.match(code, /for\s*\(\s*let\s*i\s*=\s*count\s*;\s*i\s*>\s*0\s*;\s*false\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
/*while (rows.length < count) {
rows.push(padRow(rows.length + 1, count));
}*/
--fcc-editable-region--
for (let i = count; false; false) {
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,57 @@
---
id: 660f4ae5b3924c3fc3373973
title: Step 92
challengeType: 0
dashedName: step-92
---
# --description--
Your iteration statement is also going to be different. Instead of adding `1` to `i` with each loop, you need to subtract `1`.
Like you did earlier with `i = i + 1`, update your iteration statement to give `i` the value of subtracting `1` from itself.
# --hints--
Your `for` loop should use `i = i - 1` as the iteration.
```js
assert.match(code, /for\s*\(\s*let\s*i\s*=\s*count\s*;\s*i\s*>\s*0\s*;\s*i\s*=\s*i\s*-\s*1\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
/*while (rows.length < count) {
rows.push(padRow(rows.length + 1, count));
}*/
--fcc-editable-region--
for (let i = count; i > 0; false) {
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,76 @@
---
id: 660f4b33e2a3364094ecb540
title: Step 93
challengeType: 0
dashedName: step-93
---
# --description--
Again, push the result of calling `padRow` with your `i` and `count` variables to your `rows` array.
Open up the console to see the upside-down pyramid.
# --hints--
Your `for` loop should call `rows.push()`.
```js
assert.match(code, /for\s*\(\s*let\s*i\s*=\s*count\s*;\s*i\s*>\s*0\s*;\s*i\s*=\s*i\s*-\s*1\s*\)\s*\{\s*rows\.push\(/);
```
You should call `padRow()` in your `.push()` call.
```js
assert.match(code, /for\s*\(\s*let\s*i\s*=\s*count\s*;\s*i\s*>\s*0\s*;\s*i\s*=\s*i\s*-\s*1\s*\)\s*\{\s*rows\.push\(\s*padRow\s*\(/);
```
You should pass `i` as the first argument to your `padRow()` call.
```js
assert.match(code, /for\s*\(\s*let\s*i\s*=\s*count\s*;\s*i\s*>\s*0\s*;\s*i\s*=\s*i\s*-\s*1\s*\)\s*\{\s*rows\.push\(\s*padRow\s*\(\s*i/);
```
You should pass `count` as the second argument to your `padRow()` call.
```js
assert.match(code, /for\s*\(\s*let\s*i\s*=\s*count\s*;\s*i\s*>\s*0\s*;\s*i\s*=\s*i\s*-\s*1\s*\)\s*\{\s*rows\.push\(\s*padRow\s*\(\s*i\s*,\s*count\s*\)\s*\)/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
/*while (rows.length < count) {
rows.push(padRow(rows.length + 1, count));
}*/
--fcc-editable-region--
for (let i = count; i > 0; i = i - 1) {
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,63 @@
---
id: 660f4b641290da41b2cf0dd9
title: Step 94
challengeType: 0
dashedName: step-94
---
# --description--
Just like addition, there are different operators you can use for subtraction. The <dfn>subtraction assignment</dfn> operator `-=` subtracts the given value from the current variable value, then assigns the result back to the variable.
Replace your iterator statement with the correct statement using the subtraction assignment operator.
# --hints--
Your `for` loop should not use `i = i - 1`.
```js
assert.notMatch(code, /for\s*\(\s*let\s*i\s*=\s*count\s*;\s*i\s*>\s*0\s*;\s*i\s*=\s*i\s*-\s*1\s*\)\s*\{\s*rows\.push\(\s*padRow\s*\(\s*i\s*,\s*count\s*\)\s*\);/);
```
Your `for` loop should use subtraction assignment to reduce `i` by `1`.
```js
assert.match(code, /for\s*\(\s*let\s*i\s*=\s*count\s*;\s*i\s*>\s*0\s*;\s*i\s*-=\s*1\s*\)\s*\{\s*rows\.push\(\s*padRow\s*\(\s*i\s*,\s*count\s*\)\s*\);/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
/*while (rows.length < count) {
rows.push(padRow(rows.length + 1, count));
}*/
--fcc-editable-region--
for (let i = count; i > 0; i = i - 1) {
rows.push(padRow(i, count));
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,63 @@
---
id: 660f4c3b01c44743719c99e4
title: Step 95
challengeType: 0
dashedName: step-95
---
# --description--
Because you are only subtracting one from `i`, you can use the <dfn>decrement operator</dfn> `--`.
Replace your subtraction assignment with the decrement operator.
# --hints--
Your `for` loop should not use subtraction assignment.
```js
assert.notMatch(code, /for\s*\(\s*let\s*i\s*=\s*count\s*;\s*i\s*>\s*0\s*;\s*i\s*-=\s*1\s*\)\s*\{\s*rows\.push\(\s*padRow\s*\(\s*i\s*,\s*count\s*\)\s*\);/);
```
Your `for` loop should use the decrement operator.
```js
assert.match(code, /for\s*\(\s*let\s*i\s*=\s*count\s*;\s*i\s*>\s*0\s*;\s*i--\s*\)\s*\{\s*rows\.push\(\s*padRow\s*\(\s*i\s*,\s*count\s*\)\s*\);/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
/*while (rows.length < count) {
rows.push(padRow(rows.length + 1, count));
}*/
--fcc-editable-region--
for (let i = count; i > 0; i -= 1) {
rows.push(padRow(i, count));
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,63 @@
---
id: 660f4cde8dd305450514a1cb
title: Step 96
challengeType: 0
dashedName: step-96
---
# --description--
Use a multi-line comment to comment out this loop as well, to prepare for the next approach.
# --hints--
Your `for` loop should be commented out.
```js
const stripped = __helpers.removeJSComments(code);
assert.lengthOf(stripped.match(/for\s*\(/), 1);
```
Your `for` loop body should be commented out.
```js
const stripped = __helpers.removeJSComments(code);
assert.notMatch(stripped, /rows\.push/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
/*while (rows.length < count) {
rows.push(padRow(rows.length + 1, count));
}*/
--fcc-editable-region--
for (let i = count; i > 0; i--) {
rows.push(padRow(i, count));
}
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
@@ -0,0 +1,77 @@
---
id: 660f4cffb1459d45e34902d1
title: Step 97
challengeType: 0
dashedName: step-97
---
# --description--
You can actually build the inverted pyramid without needing to loop "backwards" like you did.
To do this, you'll need to learn a couple of new array methods. Start by using `const` to declare a `numbers` variable. Assign it an array with the elements `1`, `2`, and `3`. Then log the `numbers` array.
# --hints--
You should use `const` to declare a `numbers` variable.
```js
assert.match(code, /const\s+numbers/);
```
Your `numbers` variable should be an array.
```js
assert.isArray(numbers);
```
Your `numbers` array should have the elements `1`, `2`, and `3` in that order.
```js
assert.deepEqual(numbers, [1,2,3]);
```
You should log your `numbers` array.
```js
assert.match(code, /console\.log\(\s*numbers\s*\);?/);
```
# --seed--
## --seed-contents--
```js
const character = "#";
const count = 8;
const rows = [];
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
rows.push(padRow(i, count));
}*/
/*while (rows.length < count) {
rows.push(padRow(rows.length + 1, count));
}*/
/*for (let i = count; i > 0; i--) {
rows.push(padRow(i, count));
}*/
--fcc-editable-region--
--fcc-editable-region--
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```

Some files were not shown because too many files have changed in this diff Show More