Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

i don’t know why its not passing the tests but the output looks right for the 3rd test

Your code so far

function pyramid(patternCharacter,numberOfRows,facingDownwards ){
 /* (2*numberOfRows-1)-(2*i-1)/2
  let numCharacteres=(2*i-1)
  let numCharacteresqueEspacos=(2*i-1)-numberOfRows/2
  num
  
*/
let space=" ";
let fullString="";
  for(let i=1;i<=numberOfRows;++i){
   // console.log(patternCharacter)
    //(2*i-1)
    fullString+=space.repeat((2*numberOfRows-1)-(2*i-1)/2);
    fullString+=patternCharacter.repeat((2*i-1))
    fullString+=space.repeat((2*numberOfRows-1)-(2*i-1)/2)
    fullString+="\n"
    
  //for(i=1;i<=2*i-1)
  }
  return fullString
}
console.log(pyramid("o",6,false))

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

updated my code:

function pyramid(patternCharacter,numberOfRows,facingDownwards ){
 /* (2*numberOfRows-1)-(2*i-1)/2
  let numCharacteres=(2*i-1)
  let numCharacteresqueEspacos=(2*i-1)-numberOfRows/2
  num
  
*/
let space=" ";
let fullString="";
  for(let i=1;i<=numberOfRows;++i){
   // console.log(patternCharacter)
    //(2*i-1)
    fullString+=space.repeat(((2*numberOfRows-1)-(2*i-1))/2);
    fullString+=patternCharacter.repeat((2*i-1))
    fullString+=space.repeat(((2*numberOfRows-1)-(2*i-1))/2)
    fullString+="\n"
    
  //for(i=1;i<=2*i-1)
  }
  return fullString
}
console.log(pyramid("o",6,false))

last update from today:

function pyramid(patternCharacter,numberOfRows,facingDownwards ){
 /* (2*numberOfRows-1)-(2*i-1)/2
  let numCharacteres=(2*i-1)
  let numCharacteresqueEspacos=(2*i-1)-numberOfRows/2
  num
  
*/
let space=" ";
let fullString="";
if(!facingDownwards){
  for(let i=1;i<=numberOfRows;++i){
   // console.log(patternCharacter)
    //(2*i-1)
    fullString+=space.repeat(((2*numberOfRows-1)-(2*i-1))/2);
    fullString+=patternCharacter.repeat((2*i-1))
    fullString+=space.repeat(((2*numberOfRows-1)-(2*i-1))/2)
    fullString+="\n"
    
  //for(i=1;i<=2*i-1)
  }
  return fullString
}else{
  for(let i=numberOfRows;i>=1;--i){
   // console.log(patternCharacter)
    //(2*i-1)
    fullString+=space.repeat(((2*numberOfRows-1)-(2*i-1))/2);
    fullString+=patternCharacter.repeat((2*i-1))
    fullString+=space.repeat(((2*numberOfRows-1)-(2*i-1))/2)
    fullString+="\n"
    
  //for(i=1;i<=2*i-1)
  }
  return fullString
}
}
console.log(pyramid("o",6,true))

It’s hard to eyeball the spacing and newlines like this.

Try using JSON.stringify to format your output in the same way as the tests to compare more easily.

console.log(JSON.stringify(pyramid("o",6,true)))

Please don’t share screenshots, you can copy and paste your code and output into a comment here.

Can you please explain what you are trying to show here?

// running tests 3.

pyramid("o", 4, false)

should return

"\n   o\n  ooo\n ooooo\nooooooo\n"

. 4.

pyramid("p", 5, true)

should return

"\nppppppppp\n ppppppp\n  ppppp\n   ppp\n    p\n"

. // tests completed // console output " o \n ooo \n ooooo \n ooooooo \n ooooooooo \nooooooooooo\n"
thats the console output

Ok, so the tests are showing you what your output should be for a given input. Test the input and see how the test compares to your output.

Here are some basic troubleshooting steps you can follow. Focus on one test at a time:

  • What is the requirement of the first failing test?
  • What is the result of the code and does it match the requirement?

If this does not help you solve the problem, please reply with answers to these questions.

ive corrected i neded to start already with a new line and dont add the after spaces,thanks for the JSON.Stringify tip,it helped understand the wrong part