Results 1 to 6 of 6

Thread: Why wont this work?

  1. #1
    Aerials
    Guest

    Question 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>

  2. #2
    Aerials
    Guest
    Wait... Does Opera have trouble with Javascript

  3. #3
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    I dont kow JS, but all i can say is that Opera Rules, although i would reccomend testing all code in IE forst

  4. #4
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    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
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  5. #5
    Aerials
    Guest
    Thx it does help
    and opera does rule!!

  6. #6
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    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
  •  



Click Here to Expand Forum to Full Width