I use JavaScript in the cards’ edit window to hint answers, to shuffle multiple choices, and for other reasons. I run Anki on Linux desktop.
Everything worked as intended up until I installed the latest version (2.1.49). Since then JavaScript runs well only once in each deck review and then it doesn’t run at all for some note types. For other note types it runs well only for the first card and not whatsoever for the other card. I tried to troubleshoot it but I had no luck. It behaves so on reviews, on previews, and on card editing.
Here is a card example I have problems with. The JS only runs successfully only once as I described.
<div class="cards">
{{Front}}
<hr>
<span class="clarification">number of letters:</span> <span id="word-length"></span>
<br>
<span class="clarification">letters in word:</span> <span id="random-letters"></span>
</div>
<dir class="tags">
{{Tags}}
</dir>
<script>
const word = "{{Back}}";
const wordLength = document.getElementById("word-length");
wordLength.innerHTML = word.length;
const randomLetters = document.getElementById("random-letters");
var wordLetters = word;
for (var i = 0; i < (word.length)/3; i++){
const index = Math.floor(Math.random()*wordLetters.length);
if (i+1 < (word.length)/3)
randomLetters.innerHTML += wordLetters[index]+", ";
else
randomLetters.innerHTML += wordLetters[index];
wordLetters = wordLetters.slice(0, index)+wordLetters.slice(index+1)
}
</script>
Thank you.