Hi,
I’m building an app that generates quotes from a TV show, to which fans can test their knowledge of the show. e.g. who said it; from which episode, etc.
I’m having an issue with the level-selection. I have decided to have easy, medium and difficult settings.
For simplicity, I’ve only been working on one series at the moment, and when the code is right, I’ll apply it to the others.
There are three arrays:
seriesTenQuotesArrayEasy
seriesTenQuotesArrayMedium
seriesTenQuotesArrayDifficult
In short, how do I write a condition into the if / else if statement some that will trigger looping over the relevant arrays?
I’ve tried various things so far: declaring variables as onclick events; adding onchange and onclick into the HTML. And a few others.
Anyway, any help would be greatly appreciated.
The relevant HTML has three buttons for the level selection:
<h3>Choose Your Difficulty</h3>
<div class="container">
<div class="row">
<button class="levelOfDifficultyButtons" id="easy" value="easylevel" onchange="easylevel=true">Macho (Easy)</button>
</div>
<div class="row">
<button class="levelOfDifficultyButtons" id="medium" value="mediumlevel" onchange="mediumlevel=true">Mucho Macho (Medium)</button>
</div>
<div class="row">
<button class="levelOfDifficultyButtons" id="difficult">Nervosa Grande (Difficult)</button>
</div>
</div>
<p id="levelOfDifficultyNote">*Note: Easy - Quotes reference key plot markers.
<br><br>
Medium: A mixture of quotes which reference key plot markers and quotes which do not.
<br><br>
Difficult: Includes the maximum number of quotes which do not reference key plot
markers.
</p>
And here’s the relevant JS:
seriesTenQuotes.onclick = function() {
if (easylevel = true) {
for (let i = 0; i < seriesTenQuotesArrayEasy.length; i++) {
selectedQuoteArray.push(seriesTenQuotesArrayEasy[i]);
}
} else if (mediumlevel = true) {
for (let i = 0; i < seriesTenQuotesArrayEasy.length; i++) {
selectedQuoteArray.push(seriesTenQuotesArrayEasy[i]);
}
for (let i = 0; i < seriesTenQuotesArrayMedium.length; i++) {
selectedQuoteArray.push(seriesTenQuotesArrayMedium[i]);
}
// More code would go here for the difficult-level; I'm just working on the easy and medium levels so far while I'm trying to find a way that works.
}
const seriesTenClicked = document.querySelector("#select-series-ten-button-quotes");
seriesTenClicked.style.background = '#d02910';
seriesTenClicked.style.color = '#ffffff';
seriesTenClicked.disabled = true;
seriesTenClicked.style.opacity = 0.5;
}