I have to print a triangle formed of '#'.
This is my code:
function show(n){
var text ="";
for(var i=1;i<=n;i++){
for(var j=1;j<=i;j++){
text+='#';
}
console.log(text);
}
}
show(4);
For this input I get:
#
###
######
##########
But I want to get:
#
##
###
####
What is wrong in my code? Thanks
textinside the loop. So each line will be appended to the last one.for (var i = 1; i <= n; i++) { console.log('#'.repeat(i)); }.