| View previous topic :: View next topic |
| Author |
Message |
fileslasher
Joined: 25 Apr 2007 Posts: 3
|
Posted: Mon Apr 30, 2007 4:59 am Post subject: display string vertically, how? |
|
|
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 |
|
 |
|
|
mwa103 100+ Club
Joined: 07 Mar 2005 Posts: 206
|
Posted: Mon Apr 30, 2007 8:23 pm Post subject: Re: display string vertically, how? |
|
|
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 |
|
 |
fileslasher
Joined: 25 Apr 2007 Posts: 3
|
Posted: Mon Apr 30, 2007 11:10 pm Post subject: Re: display string vertically, how? |
|
|
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 |
|
 |
|