Help with Incremental Cloze Reveal

You have a function that gets called onclick named revealCloze(i);. This same function could also hide the cloze again. For that you would:

  • add an if statement checking if the .cloze had been revealed,
  • change the cloze’s text back to what it was before revealing and
  • then declare that the cloze is not revealed anymore:
function revealCloze(i) {
  if (!revealed[i]) {
    elements[i].innerHTML = clozes[i];
    revealed[i] = true;
  } else if (revealed[i]) {
    elements[i].innerHTML = "[...]";
    revealed[i] = false;
  }
}
2 Likes