I have an array of Spanish sentences, all of which include one instance of "por" or "para" (capitalized or not). I'm trying to load one random sentence on the browser, replacing the test case of por/para for question marks ("???"). Thus far it's loading the original sentence without applying the character operation.
function setSentence() {
// Return random int between min (included) and max (excluded)
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
const sentenceList = [
"El mundo era tan reciente, que muchas cosas carecían de nombre, y para mencionarlas había que señalarías con el dedo.", "Melquíades, que era un hombre honrado, le previno: «Para eso no sirve.»", "Úrsula Iguarán, su mujer, que contaba con aquellos animales para ensanchar el desmedrado patrimonio doméstico, no consiguió disuadirlo.",
];
var sentence = sentenceList[getRandomInt(0, sentenceList.length)];
var $sentence = $("#test-sentence");
var testSentence = sentence;
if (testSentence.includes("por ") || testSentence.includes("Por ")) {
if (testSentence.includes("por ")) {
testSentence.replace("por ", "???");
} else {
testSentence.replace("Por ", "???");
}
} else {
if (testSentence.includes("para ")) {
testSentence.replace("para ", "???");
} else {
testSentence.replace("Para ", "???");
}
}
$sentence.text(testSentence);
}
setSentence();
And the html:
<div class="container">
<p><span id="test-sentence"></span></p>
</div>