: Javascript. Tree of hash char I'm newbie in javascript. I'm trying to do a tree of hash ("#") in javascript. The output I would to have is something like: # ## ### #### ##### ###### ####### I
I'm newbie in javascript. I'm trying to do a tree of hash ("#") in javascript. The output I would to have is something like:
#
##
###
####
#####
######
#######
I know how increment the line with "for" cycle;
This is my code:
var s = "#######";
for (i = 0; i <s.length; i++)
console.log(s);
But I don't understand how can decrement the char "#" by string.
Can someone please explain this to me.
More posts by @Kimberly868
1 Comments
Sorted by latest first Latest Oldest Best
Modifying your existing code, try the following:
var s = "#######";
for (i = 0; i <s.length; i++) {
console.log(s.substring(0,i));
}
The substring() method of the string object (ie. your var s) returns a portion of the string starting at 0 (the first char) and ending at i, which increases by 1 for each iteration of your for() loop.
But I don't understand how can decrement the char
Should be increment.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.