I'm looking for feedback/insight on using console.log instead of document.write to solve the looping triangle with a space in the CS50 Mario style problem.
Triangle loop - CS50 mario style
var str = "#";
var height = 8;
for (var i = 0; i < height; i++) {
for (var j = 0; j < height-i-1; j++) {
document.write("_");
}
{
for (var k = 0; k < i + 2; k++) {
document.write(str);
}
document.write("<br />");
}
}
//
_______##
______###
_____####
____#####
___######
__#######
_########
#########
The document.write(“_”) is because the DOM trims any white space so (“ “) won't work - took me ages to figure that out.
I can’t get the triangle to come out right aligned using console.log() instead of document.write - any thoughts?
Cheers - I'm a huge SOF fan for learning.