JSFiddle - React, Tailwind, and code Playground
HTML
<div id="whatever"></div>
JavaScript
function quine(phrase) {
if (phrase.split("X").length != 2) {
throw "Input phrase must contain exactly one occurrence of X";
}
var inner = phrase.replace(
"X",
"X, with the first X replaced by the previous quoted sentence" +
((phrase.indexOf("X ") == -1) ? "" : ","));
return inner.replace("X", '"' + inner + '"') + ".";
}
function showQuine(phrase) {
var p = document.createElement("p");
p.innerHTML= quine(phrase);
document.getElementById("whatever").appendChild(p);
}
showQuine("X is false");
showQuine("Products marked with X can be heated at your request");
showQuine("I believe in the sentence X");
showQuine("If X is wrong, then I don't want to be right");
showQuine("I don't think X means what you think it means");