Hello. I need to create a script that takes a word from the first field of the card, modifies the sentence from the second field, and displays the modified result.
The script on the front side should replace the word with underscores. On the back, it should wrap the word in <b></b> tags to make it bold. Example:
Word: weather
Sentence: The weather yesterday was good.
Front side output: The ___ yesterday was good.
Back side output: The weather yesterday was good. (The <b>weather</b> yesterday was good)
I wrote some code that works well in browsers, but it doesn’t work in the Anki app. Could somebody, please, help me to understand why it doesn’t work?
Front side:
<div>Front</div><hr><br>
<div class="word" style="display:none">{{Word}}</div>
<div class="sentence" style="display:none">{{Sentence}}</div>
<div class="output1"></div>
<script>
let word = document.querySelector(".word").textContent;
let sentence = document.querySelector(".sentence").textContent;
document.querySelector(".output1").textContent = sentence.replace(word, "___");
</script>
Back side:
<div>Back</div><hr><br>
<div class="word" style="display:none">{{Word}}</div>
<div class="sentence" style="display:none">{{Sentence}}</div>
<div class="output2"></div>
<script>
let word = document.querySelector(".word").textContent;
let sentence = document.querySelector(".sentence").textContent;
document.querySelector(".output2").innerHTML = sentence.replace(word, "<b>" + word + "</b>");
</script>