Learn Introductory JavaScript by Building a Pyramid Generator - Step 104

Tell us what’s happening:

The test requires to check if inverted is true , and requires to do that without using any equality operator
What should I do

Your code so far

const character = "#";
const count = 8;
const rows = [];
let inverted = true;

function padRow(rowNumber, rowCount) {
  return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}

// TODO: use a different type of loop

// User Editable Region

for (let i = 1; i <= count; i++) {}
if(iverted){
  console.log(iverted);
}

  rows.unshift(padRow(i, count));
}

// User Editable Region


/*while (rows.length < count) {
  rows.push(padRow(rows.length + 1, count));
}*/

/*for (let i = count; i > 0; i--) {
  rows.push(padRow(i, count));
}*/

let result = ""

for (const row of rows) {
  result = result + "\n" + row;
}

console.log(result);

Your browser information:

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 15_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/119.0.6045.169 Mobile/15E148 Safari/604.1

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 104

write inverted correctly, you are missing the n in both places

1 Like

Ohh silly me :sweat_smile:
Thanks much

I did corrected the spelling,
But The test does not pass ?

please show your code now

image

no, please post your code not a screenshot

Sorry I’m new here how can Post my code again ?

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

If(inverted) {
Console.log(inverted)}

you should copy and paste the code,
the code you have posted has various syntax issues

please post all the code you have in the editor, I need it to test your code

 const character = "#";
const count = 8;
const rows = [];
let inverted = true;

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++) {}
if(inverted){
  console.log(inverted);
}

  rows.unshift(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));
}*/

let result = ""

for (const row of rows) {
  result = result + "\n" + row;
}

console.log(result);

pasting this code in the editor makes a syntax error appear, does it not appear for you in the console?

SyntaxError: unknown: Unexpected token (17:0)

  15 |
  16 |   rows.unshift(padRow(i, count));
> 17 | }
     | ^
  18 |
  19 | /*while (rows.length < count) {
  20 |   rows.push(padRow(rows.length + 1, count));

you have an extra closing }

and

I think the one on this line is the extra one, considering that the if should go inside the for loop

1 Like

Yup it was the extra closing
I removed it the test passed
Thanks :blush:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.