Tell us what’s happening:
i think i did well yet , but i don’t pass . what should i do more than that ? could anyone give hint ?
Your code so far
function pyramid(str, num, bool) {
for(let i = 0; i < num; i++) {
let row = ''
if(!bool) {
for(let j = 0; j < num - i - 1; j++) {
row += ' '
}
} else {
for(let j = num; j > num - i - 1; j--) {
row += ' '
}
}
if(!bool) {
for(let k = 0; k < 2 * i + 1; k++) {
row += str
}
} else {
for(let k = 2 * num - 2; k > 2 * i - 1; k--) {
row += str
}
}
console.log(row)
}
}
pyramid('o', 5, false)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator
https://www.freecodecamp.org/learn/full-stack-developer/lab-pyramid-generator/lab-pyramid-generator
ILM
August 12, 2025, 8:38am
2
what is your function returning?
if i return i don’t get the output that i want i just log it on the console
ILM
August 12, 2025, 8:47am
4
But what do the user stories say?
like, User story 5 starts with “The pyramid function should return”, the tests also use “should return”
are you sure your approach is correct?
1 Like
hi @SamehCode01
pyramid("o", 4, false) should return "\n o\n ooo\n ooooo\nooooooo\n".
Do you add a newline character to the beginning of each line?
To test you can print the raw output with:
console.log(JSON.stringify(row));
ILM
August 12, 2025, 8:49am
6
instead of this, you should log the function call, console.log(JSON.stringify(pyramid("o", 4, false)));
1 Like
Indeed we need to aggregate the rows to return.
um no iam not sure cuz of your words i feel i walk in the wrong way . did u observed my code and how i managed somethings like true false with ! in condition , that was genius from me i feel good with this what u c boss ?
oic i will try to rebuild it again , thank you
ILM
August 12, 2025, 9:37am
10
you need a good job with that, now you need to figure out how to create a string to return instead of using console.log for each row
1 Like
Just to add to what’s been said already.
To see the returned output as a pyramid:
console.log(pyramid('o', 5, false))
To see the returned output as a RAW string to compare with the tests:
console.log(JSON.stringify(pyramid("o", 5, false)));
Both are useful
1 Like
i need to storm my brain first for a while
to be honest i searched for this problem on google and i observed solution but i did not copy the code i manipulate it myself , in addition to conditions i added and manipulate reversing pyramid depending on true/false all that i did myself
now i try to build it from scratch again , but i still meet a problem somehow should i observe it again for review ?
ILM
August 12, 2025, 2:52pm
15
no, keep trying on your own, use the output to know what you need to change
if you know what you need to change but don’t know how, you can ask for help
i will try to discover it my self
look how i test it on the console
console.log(hasPassingGrade(getGrade(getAverage([38, 99, 87, 100, 100, 100, 100, 100, 100, 100]))))
oO seems i mixed the problem with another challenge
ILM
August 12, 2025, 4:41pm
18
that does not look like a function call you would use in this lab
yea i missed up , i was just working with gradebook app . wohoooo i just passed it right now , you know this feeling man , this feeeeeeeeeeling after success
no man i can’t do that . i feel my brain stopped working like computer bugs . i think i will bookmark those challenges and i will practice it more in the future