| Author |
looping letters in javascript |
ranma
Member

Posts: 269
Location: Behind a sphere
Joined: 27.08.05 Rank: HBH Guru |
|
|
how do you loop letters in javascblockedript? |
|
| Author |
RE: looping letters in javascript |
HopelessRomantic
Member
Posts: 71
Location: Lost in my own cryptic thoughts.
Joined: 14.04.06 Rank: Uber Elite |
|
I don't know personally but check out http://www.w3schools.com they might have something about that.
"Judge not by age but by maturity" |
|
| Author |
RE: looping letters in javascript |
Jake
Member
Posts: 107
Location: United States
Joined: 13.12.04 Rank: God |
|
What do you mean exactly?
Like:
<scblockedript>
for( i = 0; i <= 10; i++ )
document.write('a');
</scblockedript>
?
|
|
| Author |
RE: looping letters in javascript |
wolfmankurd
Member

Posts: 1519
Location: UK
Joined: 30.05.05 Rank: God |
|
doesnt that write i 10 times? i think he means without the increment
BY READING MY POST, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE USE OF THIS (MIS)INFORMATION.

|
|
| Author |
RE: looping letters in javascript |
BobbyB
Member

Posts: 260
Location: England
Joined: 16.03.05 Rank: Monster |
|
I'm not quite sure, but I think he wants to loop through different letters. There would be a couple of ways to do this, one would be to use a String.fromCharCode(int) function in a for loop.
String.fromCharCode(i) returns the character of the ascii value of i;
For example, String.fromCharCode(65) returns a capital A.
Stick this in a for loop, like so:
<scblockedript>
for (x = 65; x <= 81; x++)
{
document.write(String.fromCharCode(x));
}
</scblockedript>
This would print every character from capital A to capital Q.
Another way to do it would be to make a string of all the characters you wish to loop through, then loop through every character in the String.charAt(int) method. This returns the character that is number int in the string, for example
<scblockedript>
var chocka = "absdfty152634k";
for (i = 0; i < chocka.length; i++)
{
document.write(chocka.charAt(i));
}
</scblockedript>
This loops through every character in the string Chocka and prints them.
Edited by BobbyB on 23-04-06 15:43 |
|