|
-
Apr 18th, 2002, 06:46 PM
#1
Why wont this work?
Im trying to make a script that asks for words then prints them out. It first asks how many words then asks what each word is.
<script language="javascript">
var words=prompt("How many words?","");
for(loop=0;loop<words;loop++)
{
var loop1=loop+1;
var wordx=prompt("What's word " + loop1);
var all="<h1>In Reverse</h1><br>word :" + loop1 +"<br>" + wordx;
}
var new=open("test4.html","new","width=400, height=400");
new.document.writeln(all);
</script>
-
Apr 18th, 2002, 07:15 PM
#2
Wait... Does Opera have trouble with Javascript
-
Apr 18th, 2002, 07:38 PM
#3
Fanatic Member
I dont kow JS, but all i can say is that Opera Rules, although i would reccomend testing all code in IE forst
-
Apr 19th, 2002, 04:39 AM
#4
Fanatic Member
Hi,
I fixed your script, theres a couple of things missing so try to explain:
First thing I noticed is that the script only displays the last value you input, thats because in the loop the all variable kept getting overwritten with a new value. To fix this I created an array to keep the values in.
I also noticed that a new window wasn't been created because you gave it the code a variable called new but this isn't allowed as new is a keyword.
I also moved in reverse to be printed to the new window just after its created so it doesnt get printed more than once.
Code:
<script language="javascript">
var worditems = new Array;
var words=prompt('How many words?','');
for (loop=0;loop<words;loop++){
var loop1=loop+1;
var wordx=prompt('What\'s word ' + loop1);
worditems[loop]= loop1 + '<br>' + wordx + '<br>';
}
var newwin=window.open('');
newwin.document.writeln('<h1>In Reverse</h1><br>');
for (i=0;i<words;i++){
newwin.document.writeln('word : ' + worditems[i]);
}
</script>
Hope this helps, oh, and Opera rules
-
Apr 19th, 2002, 11:42 AM
#5
Thx it does help 
and opera does rule!!
-
Apr 20th, 2002, 05:50 AM
#6
Fanatic Member
Originally posted by Aerials
opera does rule!!
lol, i'd like to hire you to stand on a street corner yelling it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|