Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


display string vertically, how?



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> JavaScript Forum
View previous topic :: View next topic  
Author Message
fileslasher



Joined: 25 Apr 2007
Posts: 3

PostPosted: Mon Apr 30, 2007 4:59 am    Post subject: display string vertically, how? Reply with quote

Hi I'm trying to display a string vertically, like this:
h
i
t
h
e
r
e

Here's my code, been messing around with it for awhile and can't figure out how to do it right.

var i = 0;
var userString = prompt("Enter a string");

while (userString.length > 0)
{
i++;
document.write(userString(i) + "<br>");
}
Back to top
View user's profile Send private message
mwa103
100+ Club


Joined: 07 Mar 2005
Posts: 206

PostPosted: Mon Apr 30, 2007 8:23 pm    Post subject: Re: display string vertically, how? Reply with quote

You're close, but you have one little error in your code. You are referencing your string length in the while loop and checking if it is > 0. This never changes so you will end up with an infinite loop. What you need to do is reference the variable that is being changed like this:

Code:
var i = 0;
var userString = prompt("Enter a string");

while (i < userString.length)
{
i++;
document.write(userString(i) + "<br />");
}


Hope this helps.

-Mike
Back to top
View user's profile Send private message MSN Messenger
fileslasher



Joined: 25 Apr 2007
Posts: 3

PostPosted: Mon Apr 30, 2007 11:10 pm    Post subject: Re: display string vertically, how? Reply with quote

That does'nt seem to work. Nothing is displaying after user prompt. I'm getting an error in firefox javascript console saying that "userString is not a function" and it highlights "document.write(userString(i) + "<br/>");

edit* I found the problem. I just needed to change userString(i) to
userSrting[i].

Thanks for your help.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> JavaScript Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap