Tell us what’s happening:
Hi, I’ve written the logic out in my code comments. I believe I’m on the right lines but to begin with I’m trying to iterate down the amount of spaces I need. I’m very confused by this but it’s a great challenge and am learning a lot about using a pen and paper to work out the logic.
Your code so far
/*
if 4 rows
0 begin with enter
1 inputNumber(4-1=3) spaces + letter(1) + enter // 3 spaces + 'p' + enter
2 aboveLine(3-1=2) spaces + letter+2(3) + enter // 2 spaces + 'ppp' + enter
3 aboveLine(2-1=1) spaces + letter+2(5) + enter // 1 spaces + 'ppppp' + enter
4 aboveLine(1-1=0) spaces + letter+2(7) + enter // 0 spaces + 'ppppppp + enter
5 end with enter
then use .join to join as one sentence.
*/
function pyramidMaker(rows, char) {
let space = "s p";
console.log(space)
for (let i = rows; i >= 0; i--) {
console.log(i)
}
}
console.log(pyramidMaker(4, "p"));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator
Where do you need a help exactly?
Iterating down the spaces, so if space was ‘-’, making the amount of spaces go - - -, - -, -
I understand the task, but what I see is you barely started the code, but you have a plan to execute.
Since you used the “asking for help” option, it makes me think you need help with your current code, but you didn´t described your problem yet.
Than I assume you don´t know how to start.
Test 3 and test 4 show you the output you have to generate.
For test example for text 3: "\n o\n ooo\n ooooo\nooooooo\n"
You have seen right you have to create a syntax.
Using loop is also a good approach.
What is this for in your code? let space = "s p";
the let space = “s p”; is there because I wanted to repeat the space a number of times but wouldn’t be able to see a blank space. I just have massive brain fog trying to start the code.
There are multiplie ways to complete this lab, but stick with your idea first for consistency.
You wrote: “then use .join to join as one sentence.”
So do you want the function to create an array and then turning it into a syntax?
Than just finish the logic what you created so far:
How to create the lines properly for the layers of the pyramid?
How to use your for...of loop to update the array properly?
I think leave the true/false condition after you have a basic working pyramid generator.
Yes I was imagining generating the amount of spaces needed rows - 1, adding the letter on first line then letter + 2 every line after, then adding an enter, then pushing this to an array and continuing through until the function is complete then joining the array together.
You have a very solid plan, why don´t you try to write the code right away?
The forum is here for you if you get stuck. Don´t be afraid of trying.
Thank you, I’ll keep trying!
1 Like