Tell us what’s happening:
JS fundamental review step 12 on May 27, 2026.
Ans works:
https://gist.github.com/Urbaner3/8907111595d3a7bd9cc39d4230866ddeJS fundamental review step 12 on May 27, 2026.
Ans works:
It only works if I make pyramid function return and check it in the main function part. Why is that?
It only works if I make pyramid function return and check it in the main function part. Why is that?
Your code so far
const pyramid = function (str, Nrow, bool){
let whole = "";
if(bool){
for(let i = Nrow; i > 0; i= i - 1){
whole = whole.concat("\n");
let spaces = "";
let line = "";
for(let k = 0; k< Nrow-i; k= k + 1){
spaces = spaces.concat(" ");
}
for(let j = 0; j< 2*i-1; j= j + 1){
line = line.concat(str);
}
// spaces = spaces.slice(0,Nrow-i-1);
// console.log(spaces, line);
line = spaces.concat(line);
whole = whole.concat(line);
}
whole = whole.concat("\n");
console.log(whole);
}
else{
// console.log("\n");
for(let i = 0; i< Nrow; i= i + 1){
whole = whole.concat("\n");
let spaces = "", line = "";
for(let j = 0; j< Nrow-1-i; j= j + 1){
spaces = spaces.concat(" ");
}
for(let j = 0; j< 2*(i+1)-1; j= j + 1){
line = line.concat(str);
}
// spaces = spaces.slice(0,Nrow-i-1);
// if (i < 2){
// spaces = " ";
line = spaces.concat(line);
// }
// console.log(line);
whole = whole.concat(line);
}
whole = whole.concat("\n");
console.log(whole);
}
return whole;
}
let ans = "";
let check = "";
check = pyramid("o", 4, false);
console.log("case check:", check==ans);
check = pyramid("p", 5, true);
console.log("case check:", check==ans);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator