Back to Freecodecamp

Step 78

curriculum/challenges/english/blocks/learn-introductory-javascript-by-building-a-pyramid-generator/660f415b76859a2736771607.md

latest1.4 KB
Original Source

--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(__helpers.removeJSComments(code), /if/);

Your if statement should have true as the condition.

js
assert.match(__helpers.removeJSComments(code), /if\s*\(\s*true\s*\)/);

Your if body should log "Condition is true".

js
assert.match(__helpers.removeJSComments(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 + row + "\n";
}

console.log(result);