Archive:Debugging challenges: Difference between revisions

Line 9: Line 9:
     alert("the product of " + num1 + " and " + num2 + " is " + product);
     alert("the product of " + num1 + " and " + num2 + " is " + product);
  </script>
  </script>
<script type="text/javascript">
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Patrick Fitzgerald | http://www.barelyfitz.com/ */
function truncate() {
  var len = 100;
  var p = document.getElementByID('truncateMe');
  if (p) {
    var trunc = p.innerHTML;
    if (trunc.length > len) {
      /* Truncate the content of the P, then go back to the end of the
previous word to ensure that we don't truncate in the middle of
a word */
      trunc = trunc.substring(0, len);
      trunc = trunc.replace(/\w+$/, '');
      /* Add an ellipses to the end and make it a link that expands
the paragraph back to its original size */
      trunc += '<a href="#" ' +
'onclick="this.parentNode.innerHTML=' +
'unescape(\''+escape(p.innerHTML)+'\');return false;">' +
'<span style="font-size: 10px;">[ more ... ]</span><\/a>';
      p.innerHTML = trunc;
    }
  }
}
// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
oldonload();
      }
      func();
    }
  }
}
addLoadEvent(function() {
  truncate();
});
</script>
<p id="truncateMe">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean consectetuer. Etiam venenatis. Sed ultricies, pede sit amet aliquet lobortis</p>


== Challenge 2 - Syntactic Errors ==
== Challenge 2 - Syntactic Errors ==