mercredi 5 mai 2021

How do I display a certain image when a variable reach a certain value?

The program is supposed to be similar to a buzzfeed quiz. You answer a couple of questions which change the variable poeng. Say one answer gives you +5 points and another gives you +7. Based on your final sum you get a picture and a text saying for example "You are the nerd!". The problem is I do not know how to display an image when a variable reach a certain value- as well as displaying it in an empty/new html page, if that makes sense.

var poeng = 0;

function myFunction() {
  poeng = 5;

  console.log(poeng)
  check()
}

function myFunction2() {
  poeng = 7;

  console.log(poeng)
  check()
}

function myFunction3() {
  poeng = poeng + 5;

  console.log(poeng)
  check()
}

function check() {
 if(poeng == 12) {

    console.log("Hello World");

 }
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>

<button onclick="myFunction()"> 5 </button>

<button onclick="myFunction2()"> 7 </button>

<button onclick="myFunction3()"> +5 </button>

</body>
</html>

Aucun commentaire:

Enregistrer un commentaire