User:Zuhui/SI26/Storybook/Code to work 2
< User:Zuhui | SI26 | Storybook
Revision as of 14:47, 17 February 2025 by Zuhui (talk | contribs) (Created page with "=Html structure= <syntaxhighlight lang="html"> <body> <p id="sentence"> <span class="word_do">do</span> <span class="word_tigers">tigers</span> <span class="word_melt">melt</span> <span class="word_like">like</span> <span class="word_butter">butter</span> <span class="word_in">in</span> <span class="word_the">the</span> <span class="word_forest">forest</span> <span class="word_questionmark">?</sp...")
Html structure
<body>
<p id="sentence">
<span class="word_do">do</span>
<span class="word_tigers">tigers</span>
<span class="word_melt">melt</span>
<span class="word_like">like</span>
<span class="word_butter">butter</span>
<span class="word_in">in</span>
<span class="word_the">the</span>
<span class="word_forest">forest</span>
<span class="word_questionmark">?</span>
</p>
<div id="stage">
<div class="do"></div>
<div class="tigers object"></div>
<div class="melt object"></div>
<div class="like"></div>
<div class="butter object"></div>
<div class="in"></div>
<div class="the"></div>
<div class="forest object"></div>
<div class="questionmark"></div>
</div>
<script src="java1.js"></script>
</body>
now all the divs are also siblings, so they will listen to same command that controls the spans(words)
Javascript
let sentence = document.getElementById("sentence")//this is added from the first version, in the first version, I didn’t define "sentence", so there was no way to know where to put the words back from removedWords in "bringBack"function.
let words = Array.from(document.querySelectorAll("#sentence span"));
let removedWords = [];