Find ⌊√n⌋ without a square-root function. The answer r is the largest integer with r² ≤ n. That's a monotonic condition: true up to a point, false after it. That calls for binary search:
let lo = 0, hi = n;
while (lo < hi) {
const mid = Math.ceil((lo + hi) / 2);
if (mid * mid <= n) lo = mid; else hi = mid - 1;
}
return lo;
Binary search on the answer is one of the most reusable ideas in algorithms. Whenever you can test "is X big enough?", you can search for the boundary in O(log n).