Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

I believe my code is working, and should pass the tests, but is failing test 3 and 4. I believe this is simply due to how it is being assessed. So I guess, I have two questions.

  1. Should this pass?
  2. In a real world example, since this is being assessed differently than how I logically did it, would the team lead expect me to rebuild the function in a way to pass the testing even though the results are as intended?
    2.b) If so, is there a simpler way I should have approached this?

Your code so far

function pyramid(str, num, bool) {
  let results = "";
  const space = " ";

  function rowBuild(val, itt, num) {
    const spaces = num - 1 - itt;
    const blocks = (itt * 2) + 1;

    results = results.concat(`\n${space.repeat(spaces)}${val.repeat(blocks)}`)
  }

  if (bool === false) {
    for (let i = 0; i < num; i++) {
      rowBuild(str, i, num);
    }

  } else {
    for (let i = (num - 1); i >= 0; i--) {
      rowBuild(str, i, num);
    }
    
  }
  
  return results;
}

console.log(pyramid("p",4,true));

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:145.0) Gecko/20100101 Firefox/145.0

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

Your output is not identical to the requested output. You have to put the line breaks exactly in the same place the instructions requested

1 Like

You can add this to the bottom of your script file to compare actual to expected. Your code is very close to what is expected:

console.log("Actual: ", JSON.stringify(pyramid(“o”, 4, false)));
console.log(“Expected: “, JSON.stringify(”\n o\n ooo\n ooooo\nooooooo\n”));
console.log("Actual: ", JSON.stringify(pyramid(“p”, 5, true)));
console.log(“Expected: “, JSON.stringify(”\nppppppppp\n ppppppp\n ppppp\n ppp\n p\n”));

1 Like

Aghhh. Step 9 skipped. Lesson, reread instructions before posting. lol Thanks team!

Excellent testing tip! Thank you!