I would like a random sentence (selected through a function) to appear on my HTML when we click on a button.
Here is my HTML code :
<button onclick="riddle()">Riddle</button>
<p id="Riddle"> </p>
And here is my JavaScript code:
function riddle(){
const randomRiddle = riddlesBase[Math.floor(Math.random()*20)];
document.getElementById("Riddle").innerHTML = randomRiddle;
};
If I console.log(randomRiddle), a sentence appears (a different one each time, but it doesn't do anything on the website here.
Could you tell me what is wrong and how to make it work?
Thank you,