function doIt() { // gather variable data const nth = parseInt(document.getElementById("nth").value); const expr = document.getElementById("expr").value; const respectTo = document.getElementById("respectTo").value; const answer = `${math.format( nthDerivative(expr, nth, respectTo), 14 )}`; katex.render(answer, document.getElementById("nth-derivative")); } function nthDerivative(expr, n, respectTo) { let ans = math.derivative(expr, respectTo); for (let i = 0; i < n - 1; i++) { ans = math.derivative(ans, respectTo); } return ans; }