Building a Pyramid

SunJet Liu
Jul 26, 2021
var prystring = function(char, num){
let string = '\n'
for (let i = 1 ; i <= num; i++){
for(let j = num; j > i; j--){
string += " "
}
for(let k = 0; k < i * 2 -1; k++){
string += `${char}`
}
for(let j = num; j > i; j--){
string += " "
}
string += "\n"
}
console.log(string)
}

prystring('*',5)
'
*
***
*****
*******
*********
'
var strings = function(char, num){
let string = '\n'
for (let i = 0 ; i < num; i++){
for(let j = 0; j < i; j++){
string += " "
}
for(let k = 0; k < 2 * (num-i) -1; k++){
string += `${char}`
}
string += "\n"
}
console.log(string)
}

strings('*',5)
'
*********
*******
*****
***
*
'

--

--