Loops

admin

Administrator
Staff member
I'm trying to make a 'for loop' that will go through a string, and each time a condition is met, it will bold the character it is on (which is 'string.charAt(loop)').

The problem is, I don't know how to make it do that.

First, I tried:

for (loop=0;string.length>loop;loop++)
{string.charAt(loop).bold();}

That didn't work. Then I tried:

for (loop=0;string.length>loop;loop++)
{rep_char=string.charAt(loop).bold(); // rep_char means replacement character
string.charAt(loop)=rep_char;}

Then I realized that I was probably violating some fundamental rule of JavaScript, so I gave up and decided to ask you guys how to do it. After I tried this:

for (loop=0;string.length>loop;loop++)
{rep_char=string.charAt(loop).bold();
string=string.substring(0,loop-1)+rep_char+string.substring(loop,string.length);}

Of course that didn't work. As you can see, I'm a beginner, and I really need some help. This is driving me nuts. Please help. Thanks.

Alan.
 
Back
Top