← Main book chapter 2
Contents / index
Browser back
← Previous chapter
Next chapter →
Laboratory
Memory
Cards
Sort
Match
Visuals
Coding
Quiz
Programming practice
Bisection method — Chapter 2
Fix the sign test and midpoint update.
Language:
JavaScript
Student code
function bisection(f,a,b,n){ for(let k=0;k<n;k++){ let m = (b-a)/2; if(f(a)*f(m)>0) b=m; else a=m; } return (a+b)/2; }
Check code
Show corrected code
Reset buggy code
Feedback
Corrected code