Solved

Javascript debugging

Posted on 2012-03-20
6
310 Views
Last Modified: 2012-03-21
Hi,
I have some simple code that I need to 'debug'.  I dont really know anything about javascript - so I've been trying to use various debuggers, such as JSLint, Microsoft Script Debugger etc.  I'm really struggling to get this done so wondering if someone out there could help me - you can probably identify the errors just by looking at the code... but I'm not that good!
0
Comment
Question by:eyedropp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Expert Comment

by:VisionAmp
ID: 37744576
Are you looking for a debugger or help debugging your code from EE, I don't see the code
0
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37744620
Just use firefox and install firebug free firefox plugin. This is the best & simple js debugger i have ever seen. After installing FireBug in firefox, just press F12 and open your page,it will show (in console tab) error inside the firebug.
0
 

Author Comment

by:eyedropp
ID: 37744838
Well either VisionAmp!  I thought I had attached the code.  Not sure what happened there - I'll paste it in here.

I have tried Firebug but it doesnt detect any errors for this code.  But I KNOW there are errors in it.

The code is:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<title>Multiplication Tables</title>
<style type="text/css">
body {font-family: verdana, arial, sans serif; font-size: 1em;}
p {color: #FF0000;}
</style>
</head>

<body>      
<div align="center">
<table border="0" width="95%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<!--Source: http://www.sislands.com/jscript/examples.htm-->
<h1>Multiplication Table Using Nested Loops</h1>
<script type="text/javascript" language="javascript">

    document.write("<p><b><pre>"<blockquote>")
    var  i, j, total;   // global variables

    for (id = 1; i <= 10; i++) {
       for (j = 1; j < 10; j++)
           total = i * j;
           total = " " + total   //add space before each number
           // Add another space before single digits
           if total < 10 total = " " + total;
           
          //Display result
                  document.write (total);
        } // end inner j loop
       document.write ("<br />");    // end of line break
     } // end of i outer loop
     document.write("</blockquote></pre></b></p>")

</script>
</td>
</tr>
</table>
</div>

</body>
</html>


Thanks
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 125 total points
ID: 37744909
replace your code inside <script> .. </script> with the following code

document.write("<p><b><pre><blockquote>")
  var  i, j, total;   // global variables

  for (id = 1; i <= 10; i++) {
     for (j = 1; j < 10; j++)
      {   total = i * j;
         total = " " + total   //add space before each number
         // Add another space before single digits
         if (total < 10) total = " " + total;
         
        //Display result
                document.write (total);
      } // end inner j loop
     document.write ("<br />");    // end of line break
   } // end of i outer loop
   document.write("</blockquote></pre></b></p>")

This will fix your error.
0
 
LVL 14

Assisted Solution

by:Designbyonyx
Designbyonyx earned 125 total points
ID: 37744988
Something seems fishy about this line:

for (id = 1; i <= 10; i++) {

There is no variable "id" - get rid of the "d"

for (i = 1; i <= 10; i++) {
0
 

Author Closing Comment

by:eyedropp
ID: 37746470
Fantastic - thanks for your help! The code is now doing what it should!
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question