Thanks! I should have realised that a solution for this could be implemented in JavaScript as well, allowing it to run directly in the web browser. Here is my translation of my earlier Python program to JavaScript:
let lo = 0, hi = dictionary.length - 1
const answer = document.getElementById('guess')
while (document.getElementsByClassName('correct').length === 0) {
const mid = Math.floor(lo + (hi - lo) / 2)
answer.value = dictionary[mid]
guessWord()
if (answer.placeholder.indexOf('after') !== -1) {
lo = mid + 1
} else {
hi = mid - 1
}
}
This solution is quite similar to yours. Thanks for this nice idea!