Hello, I wish to allow javasript output to read it aloud as AnkiDroid (Android) TTS, but it can only read plain texts as it is repreasented in class = shuffle ( but i want to hide it from here and the shuffled output to be read by TTS) and html texts but it cannot read html output from javasript which is generated array. So please guide me so that i can force TTS to read the shuffled options to be read aloud.
<div class="shuffle">{{Opt1}}</div>
<div class="shuffle">{{Opt2}}</div>
<div class="shuffle">{{Opt3}}</div>
<div class="shuffle">{{Opt4}}</div>
<div id="container"></div>
<script>
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
// Select elements using querySelectorAll and convert NodeList to array
const elements = Array.from(document.querySelectorAll('.shuffle'));
// Shuffle the elements
const shuffledElements = shuffleArray(elements);
// Add prefixes to each element's text content
const prefixedElements = shuffledElements.map((el, index) => {
el.textContent = `${['(A)', '(B)', '(C)', '(D)'][index]} ${el.textContent}`;
return el;
});
// Get the container element by ID
const container = document.getElementById('container');
// Append each element to the container
prefixedElements.forEach(el => container.appendChild(el));
// Log each element to the console (optional)
// prefixedElements.forEach(el => console.log(el.textContent));
</script>