SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    While Loop goin Loopy

    I am becomin reallly frustrated with this, In Firefox it says that i am
    Error: missing while after do-loop body
    Source File: program5.html
    Line: 62
    Source Code:
    function tablehead()
    Heres my code(the entire thing..yea sorry for those people who are against the whole thing about people posting their entire source code)

    Code:
    <html>
    <head><title>Program 5</title>
    </head>
    
    <body>
    <script language="JavaScript">
    /*
    Author: Alkaif Khan
    Stu-ID: 0422371
    Date  : 26/05/04
    */
    
    //Set the deafault value for most books and pages to zero
    var mostbooks=0;
    var mostpages=0;
    
    //This function fills in the data 
    function tabledata()
    {
      do {
        //Create random data for our table
        var booksread=Math.floor(Math.random()*16)
        var pagesread=(Math.floor(Math.random()*101)+100*booksread)
        var readername;
    
        
        //Create User prompt and hold entered data into variable readername
        readername = prompt('Please Enter The Reader Name','Enter Name Here');
    
        //Create table data
        document.write('<tr>');
        document.write('<td>'+readername+'</td><td>'+booksread+'</td><td>'+pagesread+'</td>');
        document.write('</tr>');
        
        //hold highest book read data(name and pages read) in variables
        if(booksread>mostbooks) {
          mostbooks=booksread;
          book_reader=readername;
        }
    
        if(pagesread>mostpages) {
          mostpages=pagesread;
          page_reader=readername;
        }
       
        var yesno=prompt('Do you Wish to add another reader?',
                         'please type in yes or no'
                        );
    
        while(yesno!="no")
    
        if(yesno!="no") {
          document.write('</table>');
          document.write('<br>');
          document.write('Maximum number of books read: '+mostbooks+' by '+book_reader+'<br>');
          document.write('Maximum number of books read: '+mostpages+' by '+page_reader+'<br>');
        }
    
    }
    
    //This custom function creates the table field
    function tablehead() 
    {
       document.write('<font face="verdana" size="2pt">Girls Book Club</font>');
       document.write('<table width="70%" cellspacing="1" cellpadding="1">');
       document.write('<tr>');
       document.write('<td>Name</td><td>Number of Books Read</td><td>Number of Pages read</td>');
       document.write('</tr>');
       
       //Use the second function table data to fill in the data
       tabledata();
    }
    
    tablehead()
    </script>
    
    
    </body>
    </html>

    So umm...Whats the problem?

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    Durham
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You haven't got the ending brace for the do's block.

    } while(yesno!="no");

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    Southampton, England
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please don't post the same question multiple times, it will only get it noticed for the wrong reasons, meaning people will be more reluctant to help.

    Now to the answer:
    You appear to be missing a closing } before the end of the tableData() function.
    In fact the closing } that you are missing relates to the do loop, which is what is specified in the error.

    Hope that helps,
    AjC

  4. #4
    SitePoint Addict Guimauve's Avatar
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doh! I just responded in the other thread on the same topic.

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thank you guys . I guess some of you are more awake than I.

    I have one last request, how come the ending document.write is working, the one which shows the name of the highest book reader + the number of pages read?...

    that bit is not working,

    PHP Code:
        if(yesno!="no") {
          
    document.write('</table>');
          
    document.write('<br>');
          
    document.write('Maximum number of books read: '+mostbooks+' by '+book_reader+'<br>');
          
    document.write('Maximum number of books read: '+mostpages+' by '+page_reader+'<br>');
        } 
    ah hah! i've got it(italian axcent with the exergaration of the o and t's). changed the above to:

    PHP Code:
        if(yesno="no") {
          
    document.write('</table>');
          
    document.write('<br>');
          
    document.write('Maximum number of books read: '+mostbooks+' by '+book_reader+'<br>');
          
    document.write('Maximum number of books read: '+mostpages+' by '+page_reader+'<br>');
        } 
    and voila! it worked
    Last edited by Alkaif; Aug 26, 2004 at 23:02.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •