Learn Introductory JavaScript by Building a Pyramid Generator - Step 77

Tell us what’s happening:

Please, I need help on how to make this code work.

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));
}*/


// User Editable Region

if (true) {
  "Condition is true"
}

// 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/126.0.0.0 Safari/537.36

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 77

Hi and welcome to this forum.

You will need to use the console.log statement to print the words above.

Thanks a lot, but I’ve tried it severally and it’s still not working.

Can you copy and paste your code in your next reply so we can see if there is any error? Please enclose the code in two lines of that have three consecutive backticks like this
```
Paste code here
```

This will allow us to read your code in the forum. Thanks

This is the code below:

if (true) {

"Condition is true"

}

console.log("Condition is true");

Thanks.

This string is still floating around in here not doing anything for you.

And this is not guarded by the if statement

How can I guard it by the if statement, please?
I was following the example code given, but I’m still not clear on what I need to do.

This is the example

if (condition) {
  logic
}

The example doesn’t show placing anything outside of the if statement.

But your console log is outside of the if statement.

Okay, I think I get it now.
I will do that.
Thanks.

1 Like

Here is what I tried:

if (true) {
  "Condition is true"
  console.log(true);
}

Thanks

I don’t think the instructions asked you to put a string floating around or asked you to console log the boolean literal true. What did the instructions ask you to log again?

The instruction says:

Create an `if` statement with the boolean `true` as the condition. In the body, print the string `"Condition is true"` .

Right, so… what did the instructions ask you to console log?

The string:
“Condition is true”

Ok, are you logging that string?

I logged it and this is what I got:

if (true) {
  "Condition is true"
  console.log("Condition is true");
}

Ok, we’re getting closer. Why do you have a string floating around in your code unattached to anything?

I didn’t know what to attach it to.
Can I attach it to the boolean; true?

Let me put it another way. Why is the same string there twice?

The first time, it is used as the logic of the if statement.
The second time, I was trying to log it into the console.