Javascript: Control Statements
language. Example: forgetting to put a closing curly brace at the end of an if...else.
– Semantic errors - valid code, but does not produce the results you expect. Example: using
the wrong variable or operator somewhere in your code
–
Design errors - valid code and produces the results you expect. However, your understanding
of the problem is wrong. Example: using the wrong forumla for something.
Errors - Semantic & Design
• Semantic and design errors are very similar but have dierent implications for debugging
–
A semantic error means we understand the problem and need to adjust our code to reflect
that understanding
–
A design error means we don’t understand the problem and will never be able to produce a
working program
• A design error is a more significant problem than semantic error!
Fixing Errors
• Ways to fix errors:
–
Syntax error: computer will usually give a hint as to what’s causing the problem. Go inspect
your code to see what might be wrong (generally easy, but can be incredibly frustrating)
–
Semantic error: assuming you have correct pseudocode, something in your program doesn’t
match the pseudocode. Compare the two and make sure the operations match up. This is
when you can’t believe you’ve wasted an hour verifying your pseudocode matches your
code but you mistyped a + for a *.
–
Design error: Your pseudocode is wrong. Fix the pseudocode first. There’s no specific
advice to give since this error is always problem-specific. This is when you email your
professor/supervisor/(maybe) customer for guidance.
Reptition (loops)
• Repeat an action a number of times while a condition is true
• Example shopping pseudocode:
1 While there are more items on my shopping list
2 Purchase next item and cross it off my list
• When the condition becomes false, the loop exits
• Critical part: the loop must do something that will eventually cause the condition to be false
Mark Edmonds 10