← Main book chapter 16
Contents / index
Browser back
← Previous chapter
Next chapter →
Laboratory
Memory
Cards
Sort
Match
Visuals
Coding
Quiz
Programming practice
Relative error guard — Chapter 16
Avoid division by zero in the relative error.
Language:
JavaScript
Student code
function relerr(x,xt){ return Math.abs(x-xt)/Math.abs(x); }
Check code
Show corrected code
Reset buggy code
Feedback
Corrected code