Follow us on Twitter!
The important thing is not to stop questioning. - Albert Einstein
Sunday, May 29, 2016
Navigation
Home
 Find:
 Information:
Learn
Communicate
Submit
Shop
Challenges
 Exploit:
 Programming:
 Think:
 Track:
 Patch:
 Other:
 Need Help?
Other
Members Online
Total Online: 22
Guests Online: 17
Members Online: 5

Registered Members: 93884
Newest Member: Abdelouadoud
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

looping letters in javascript

ranma
Member



Posts: 273
Location: Behind a sphere
Joined: 27.08.05
Rank:
Active User
Posted on 22-04-06 02:54
how do you loop letters in javascript?
Author

RE: looping letters in javascript


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 22-04-06 02:57
I don't know personally but check out http://www.w3schools.com they might have something about that.


Author

RE: looping letters in javascript


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 23-04-06 15:08
What do you mean exactly?

Like:
Code

<script>
    for( i = 0; i <= 10; i++ )
        document.write('a');
</script>




?


Author

RE: looping letters in javascript


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 23-04-06 15:12
doesnt that write i 10 times? i think he means without the increment


Author

RE: looping letters in javascript


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 23-04-06 15:36
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:

Code
<script>
for (x = 65; x <= 81; x++)
{
document.write(String.fromCharCode(x));
}
</script>




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

Code
<script>
var chocka = "absdfty152634k";
for (i = 0; i < chocka.length; i++)
{
document.write(chocka.charAt(i));
}
</script>




This loops through every character in the string Chocka and prints them.




Edited by on 23-04-06 15:43