lundi 11 juin 2018

Change random generated word after function is executed

I am currently working on a programme where you like or dislike a activity that is displayed on the screen. My problem: I would like the randomly generated word to change after either the thumbs down input is clicked or thumbs up input is clicked.

Here is my Javascript code:

let words = ['Food', 'Video Games', 'Movies', 'Spa', 'Sleeping'];
let word = words[Math.floor(Math.random()*words.length)];

document.getElementById("word").innerHTML = word;

function ai(){
  document.getElementById("liked").innerHTML = "LIKED";
  document.getElementById("disliked").innerHTML = "";
}

function aii(){
  document.getElementById("disliked").innerHTML = "DISLIKED";
  document.getElementById("liked").innerHTML = "";
}

Here is my HTML code:

<h1 id="word"></h1>
<h1 id="liked"></h1>
<h1 id="disliked"></h1>
<input type="image" src="thumbsup.png" class="tu" onclick="ai()">
<input type="image" src="thumbsdown.png" class="td" onclick="aii()">

Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire