Archive:Debugging challenges: Difference between revisions

wikademia>Wikademia
 
(14 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 150: Line 150:


== Challenge Set 3 - Execution Errors ==
== Challenge Set 3 - Execution Errors ==
Execution errors are impossible requests made in perfectly correct programming terms.  
Execution errors occur when the program has the correct syntax and lexicon, but you're making the wrong requests to get the results you desire.  


1
1
Line 176: Line 176:
   {
   {
     document.write("Good day!")
     document.write("Good day!")
  }
   }
   }
}
  </script>
  </script>
3
  <script type=text/javascript>
  document.write("Show the factorials from 1 to 10")
  for (i=1,fact=1;i<11;i++,fact*=i);
  {
    document.write(i+"!="+fact+"&lt;br /&gt;")
    }
  </script>
4
  <script type="text/javascript">
    var num1 = prompt("Write a number", ' ');//try number 10
    var num2 = 10;
    if( num1 > num2 ){
    document.write("The number you wrote" +num1+ " is less than 10");
    }else{
    document.write("The number you wrote" +num1+ " is more than 10");
    }
  </script>


== Challenge Set 4 - Logic Errors ==
== Challenge Set 4 - Logic Errors ==
These are errors introduced Through faulty design. Once again, the syntax is correct, but the results are unexpected. These are the hardest errors to spot, and often the most expensive to correct.
These are errors introduced Through faulty design. Once again, the syntax is correct, but the results are unexpected, usually because you haven't considered the data being processed. These are the hardest errors to spot, and often the most expensive to correct.


1
1
Line 207: 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]]