dimanche 1 janvier 2023

Selecting a value and assigning as a variable is not working

For Hangman game, I have some topics. I have "selectedTopic.value".

HTML

<div class="select">
        <label for="topics">Choose a topic:</label>

<select id="topics">
  <option value="cities">Cities</option>
  <option value="animals">Animals</option>
</select>

JS

const topicsEl = document.querySelector("#topics")

function randomTopic(){
    return topicsEl.value[ Math.floor(Math.random() * topicsEl.value.length)].toUpperCase()
}

When I assign "selectedTopic.value" to a Math Random, the result is a letter. How can I use "selectedTopic.value" as a variable for Math random?




Aucun commentaire:

Enregistrer un commentaire