Implement the calibration loop entirely in JavaScript.