www.webdeveloper.com
Results 1 to 2 of 2

Thread: Output coming in one line on screen, but differently in Firebug or Developer Tool Bar

  1. #1
    Join Date
    Apr 2008
    Posts
    84

    Output coming in one line on screen, but differently in Firebug or Developer Tool Bar

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" >
    <title>Assignment 5 - JavaScript Loops</title>
    <head>
    <script type="text/javascript">
    
    function getGrade(){
    var i= Number(document.getElementById("input1").value);
    m=Math.floor(i/2);
    for(var k=1; k<=i; k++){
    for(var j=1; j<=k; j++){
    document.write(j+" ");
    if(j==k){
    document.write("\n");
    }
    if(j==i){
    decreaseLoop(j, k);
    }
    
    }
    }
    function decreaseLoop(j, k){
    for(k=k-1; k>0; k--){
    for(var l=1; l<=k; l++){
    document.write(l+" ");
    if(l==k){
    document.write("\n");
    }
    }
    }
    }
    }
    
    </script>
    <style type="text/css">
    
    #main{
    
    margin:auto;
    width:70&#37;;
    }
    
    #top{
    font-size:20px;
    font-weight:bolder;
    color:#007700;
    text-decoration:underline;
    }
    
    #s1{
    font-size:20px;
    font-weight:bold;
    color:#7700ff;
    }
    
    #s2{
    font-size:20px;
    font-weight:bold;
    color:#00ff00;
    }
    
    #s3{
    font-size:20px;
    font-weight:bold;
    color:#ff0000;
    }
    
    #form1{
    width:600px;
    height:80px;
    padding:20px;
    background-color:#aaaaaa;
    
    }
    
    </style>
    </head>
    
    <body>
    <div id="main">
    <p id="top">Assignment 5 - JavaScript Loops</p>
    <span id=s1>This is Form for checking Loop</span>
    
    <form id=form1 name=form1>
    <table>
    <tr><td>Enter Number </td><td>: <input type="text" id=input1 name="input1" /></td></tr>
    
    <tr><td><input type="button" name=btn1 value="Get Number" onclick=getGrade() /></td></tr>
    
    </table>
    </form>
    </div>
    </body>
    </html>
    When I execute this code, on the screen I see all output in one line. Which is not hat I want.
    But when I see it in Firebug (for firefox)or Developer Tool Bar(for IE) , I see it printed out in pyramid form(as required).
    So why is this output in one line on screen ? How cn I get it in pyramid form ?

    Thanks

  2. #2
    Join Date
    May 2005
    Location
    Dirty Jersey
    Posts
    1,402
    the "output on the screen" is done in HTML.

    HTML doesn't recognize "\n" to mean anything except that litteral character sequence.

    you'd have to use HTML to create breaks "on the screen".

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles