Eeve
1
Tell us what’s happening:
i think i get the desired result, but where did i got wrong?
Your code so far
function pyramid(str,integer,boolean){
let result = [];
if (boolean === true){
for (let i=integer; i>=0; i--){
result.push(" ".repeat(integer - i) + str.repeat(1.8*i))
}
}
if (boolean === false){
for (let i=0; i<=integer; i++){
result.push(" ".repeat(integer - i) + str.repeat(1.8*i))
}
}
return result.join("\n");
}
console.log(pyramid("o", 4, false));
console.log(pyramid("p", 5, true));
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
one of the failed messages you have says:
pyramid("o", 4, false) should return "\n o\n ooo\n ooooo\nooooooo\n".
See how it starts with a newline?
In your case, do you think what you are making starts with a newline?
(also note the ending newline)
This is as per this instruction that was given
- The pyramid should start and end with a newline character.
Edit: also you should double check the spaces you are using. I think you are outputting an extra line of spaces
Eeve
3
function pyramid(str,integer,boolean){
let result = [];
if (boolean === false){
for (let i=0; i<integer; i++){
result.push(" ".repeat(integer - i -1) + str.repeat(i * 2 + 1))
}
}
if (boolean === true){
for (let i=integer; i>0; i--){
result.push(" ".repeat(integer - i) + str.repeat(i * 2 - 1))
}
}
return "\n" + result.join("\n");
}
console.log(pyramid("o", 4, false));
console.log(pyramid("p", 5, true));
still not passing
ILM
4
try changing your logging to
console.log(JSON.stringify(pyramid("o", 4, false)));
console.log(JSON.stringify(pyramid("p", 5, true)));
so you can confront the strings in the same format they are shown in the hints
1 Like