Archive:Debugging challenges: Difference between revisions
wikademia>Anubis au |
wikademia>Wikademia m moved Debugging Challenges to Archive:Debugging challenges |
||
| (16 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) | ||
{ | { | ||
document.write("C is the largest, followed by B"); | |||
} | } | ||
else | else | ||
{ | { | ||
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"); | |||
} | } | ||
</script> | </script> | ||
| Line 150: | Line 150: | ||
== Challenge Set 3 - Execution Errors == | == Challenge Set 3 - Execution Errors == | ||
Execution errors | 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 | |||
<script type="text/javascript"> | <script type="text/javascript"> | ||
var weekdays=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") | var weekdays=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") | ||
| Line 157: | Line 158: | ||
{ | { | ||
document.write(weekdays[i] + ", "); | document.write(weekdays[i] + ", "); | ||
} | } | ||
</script> | |||
2 | |||
<script type="text/javascript"> | |||
var d = new Date(); | |||
function saygidday() { | |||
var d; | |||
var time = d.getHours(); | |||
if(time < 10) | |||
{ | |||
document.write("Good morning!") | |||
} | |||
else | |||
{ | |||
document.write("Good day!") | |||
} | |||
} | |||
</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+"<br />") | |||
} | |||
</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> | </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 178: | Line 219: | ||
{ | { | ||
document.write("The number is " == i) | document.write("The number is " == i) | ||
document.write(" | document.write("<br />") | ||
} | } | ||
</script> | </script> | ||
| Line 186: | Line 227: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
var a=2; | var a=2; | ||
document.write("We are going to see if a=4 <br />"); | |||
if(a=4) | if(a=4) | ||
{ | { | ||
document.write("Yes, variable a does equal 4"); | |||
} | } | ||
else | else | ||
{ | { | ||
document.write("No, variable a does not equal 4") | |||
} | } | ||
</script> | </script> | ||
[[Category:Programming]] | |||