Tell us what’s happening:
Any expert around to check if I’m doing the right thing .Seems i don’t really understand this project
Your code so far
//console.log(`\n o\n ooo\n ooooo\nooooooo\n`)
//console.log("\nppppppppp\n ppppppp\n ppppp\n ppp\n p\n")
function pyramid(string,integer,boolean){
for (let index = 1; index <= integer; index++) {
//console.log(index)
if (index % 2!== 0 ) {
let strPyramid =`${string.repeat(index)}`
console.log(strPyramid) //'o', 'ooo', 'ooooo'
}
}
}
console.log(pyramid(`o`,5))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.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
Welcome to the forum
I’ll take a look, but do you have a specific problem or question?
It looks like you are on the right track.
If you are wondering why you are getting “undefined”:
You are using console.log() within your function, so it is outputting right to the console.
Then you use console.log() when you call your function. Your function does not return anything so that console.log() sends undefined
If you look at the instructions:
The pyramid function should return a string
Your function should return a string, not send anything to the console.
my main issue is how to create the new lines and the empty spaces sir. it seems the empty spaces increases by itself and also Odin’s returned string is also not limited to the integer.
sorry if my English isn’t that good
with the console.log i was just testing it out please
If you look at the tests, it will show you the string structure clearly, including how to write newlines. Does that help?
This is why you need to ask questions or explain what you need. Otherwise I will end up explaining the wrong thing.
system
Closed
January 15, 2026, 4:39am
8
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.