Learn Introductory JavaScript by Building a Pyramid Generator - Step 78

Tell us what’s happening:

I get this message in the console:

Your if statement should use the equality operator to compare done and count in the condition.

The code looks like this:

while (continueLoop) {
done++;
if (done == count)
logic

What am I missing?

Your code so far

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;


// User Editable Region

while (continueLoop) {
done++;
if (done == count)
logic
}

// User Editable Region


let result = ""

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

console.log(result);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 78

Hi there and welcome to our community!

You should be creating an empty if statement for this step (i.e. a condition but not yet with any code to be executed if the condition is met). You have the condition but you also need an empty pair of curly brackets to accompany it. Nothing else.

So to be sure, if I understood correctly.
An empty if statement is

if ( )

and brackets are [ ]
and the curly brackets are { }

But it is already inside the curly brackets, as far as I can see?

You’ll need an additional set of curly brackets just for the if statement.

EXAMPLE:

myFunction() {
  if (condition) {
   // logic goes here
  }
}

Aaah okay. Thanks. It solved the whole problem!

But why do I need to have additional set of curly brackets when I have to but in the if statement? I haven´t had any need to do that in previous steps.

When you have an if condition with a single line of code to be executed, it’s not always necessary to include the curly braces. However, if you have a code block which is to be executed following a condition, the curly braces are essential.

EXAMPLE:

// curly braces not essential
if (a == 5) console.log(a);

// curly braces essential
if (a == 5) {
 a++;
 console.log(a);
}

That makes sense. And in my case, I have a code block which is to be executed following a condition. Thanks a lot !

1 Like

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