js notes on Random selector
js notes on Random selector
Focus() → This line sets the focus on the textarea element, meaning the user can immediately start
Adds an event listener to the textarea that listens for the keyup event (when a key is released
after being pressed)
createTags(e.target.value)
his function turns the comma-separated input into tags (like labels or pills shown on the
screen)
after 10 milliseconds, the value inside the textarea is cleared. As given in block
randomSelect()
Splits the input string into an array of substrings, using the comma (,) as a delimiter.
For example, "apple, banana , orange" → ["apple", " banana ", " orange"]
Ensures we’re not just stacking new tags on top of old ones.
highlightTag(tag) →
unHighlightTag(tag) →
const times = 30
Sets how many times the tags will be rapidly highlighted or unhighlighted.
Multiply by tags.length to scale that number to the range of valid indexes in the tags list.
Math.floor() rounds it down to the nearest whole number (so you get a valid index).
The final result is one random tag element from the list.