i need some help with this i have the right ouput but it cant pass
Your code so far
function pyramid(str,num,bol){
if (bol === true){
for (let i=1;i <= num;i++){
let space=' '.repeat(num - i);
let mid=str.repeat(2 * i - 1);
let result =space + mid + space;
console.log(result)
}
}else {
for (let i=num;i >= 1;i--){
let space=' '.repeat(num - i);
let mid=str.repeat(2 * i - 1);
let result =space + mid + space;
console.log(result)
}
}
}
console.log(pyramid('p', 4,true))
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
is this exercise passable? cause i think am stuck.
Your code so far
function pyramid(str, num, bol) {
let lines = [];
let width = 2 * num - 1;
if (bol === true) {
for (let i = 1; i <= num; i++) {
let row= 2 * i -1
let space = ' '.repeat(Math.floor((width - row) / 2));
let mid = str.repeat(row);
let result = space + mid + space;
lines.push(result)
}
} else {
for (let i = num; i >= 1; i--) {
let row= 2 * i -1
let space = ' '.repeat(Math.floor((width - row) / 2));
let mid = str.repeat(row);
let result = space + mid + space;
lines.push(result)
}
}
return lines.join('\n');
}
console.log(pyramid('o', 4, true))
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
In future, please do not open multiple topics to ask about the same challenge or lab. Instead use the topic you have opened for it already to update us on your questions and code.