Archive:Debugging challenges: Difference between revisions

wikademia>Wikademia
 
(10 intermediate revisions by 3 users not shown)
Line 2: Line 2:
== Challenge Set 1 - Lexical Errors ==
== Challenge Set 1 - Lexical Errors ==
Lexical errors are introduced when the programmer enters symbols that are not part of the programming language. Unlike when you misspell a word in English, this inevitably leads to a breakdown in programming communications. See if you can see (or find) the lexical errors in the following code snippets...
Lexical errors are introduced when the programmer enters symbols that are not part of the programming language. Unlike when you misspell a word in English, this inevitably leads to a breakdown in programming communications. See if you can see (or find) the lexical errors in the following code snippets...
 
{{ntoc}}
1
1


Line 50: Line 50:
  if(a>b && b>c || c>a)
  if(a>b && b>c || c>a)
  {
  {
alert("C is the largest, followed by B");
  document.write("C is the largest, followed by B");
  }
  }
  else
  else
  {
  {
alert("I am unsure what happened");
  document.write("I am unsure what happened");
  }
  }
  </script>
  </script>
Line 106: Line 106:
  if(a=>b)
  if(a=>b)
  {
  {
document.write("Yes, A is equal to or greater than B");
  document.write("Yes, A is equal to or greater than B");
  }
  }
  </script>
  </script>
Line 186: Line 186:
   for (i=1,fact=1;i<11;i++,fact*=i);  
   for (i=1,fact=1;i<11;i++,fact*=i);  
   {
   {
     document.write(i+"!="+fact+"&lt;br&gt;")
     document.write(i+"!="+fact+"&lt;br /&gt;")
     }
     }
   </script>
   </script>
Line 227: Line 227:
  <script type="text/javascript">
  <script type="text/javascript">
  var a=2;
  var a=2;
  alert("We are going to see if a=4");
  document.write("We are going to see if a=4 &lt;br /&gt;");
  if(a=4)
  if(a=4)
  {
  {
document.write("Yes, variable a does equal 4");
  document.write("Yes, variable a does equal 4");
  }
  }
  else
  else
  {
  {
document.write("No, variable a does not equal 4")
  document.write("No, variable a does not equal 4")
  }
  }
  </script>
  </script>
[[Category:Programming]]