JSFiddle - React, Tailwind, and code Playground
JavaScript
var text = ["Plato", "writes", "the", "dialogues", "of ", "the", "Early", "Period:", "Apology", "Charmides", "Crito", "Euthyphro", "Hippias Minor", "Ion", "Laches", "Protagoras", "And"];
var blankNum = Math.random(Math.floor() * (text.length / 2));
var blanks = [];
for (i = 0; i < blankNum; i++) {
var blank = Math.random(Math.floor() * (text.length / 2));
for (i = 0; i < blanks.length; i++) {
if (blank != blanks[i]) {
break;
}
else {
blank = Math.random(Math.floor() * (text.length / 2));
i = 0;
}
blanks.push(blank);
}
var finalText = "";
var textPrelim;
for (i = 0; i < text.length; i++) {
var currentText = text[i];
for (i = 0; i<blanks.length; i++){
if (currentText==blanks[i]){
textPrelim = <input type="text"></input>
finalText = finalText + textPrelim;
}
else {
textPrelim = currentText;
finalText = textPrelim + finalText;
}
}
}
}
document.getElementById('text').innerHTML = finalText;