307- Exercice 4

by TwigoLeBG

HTML

<html>
<header>
  
</header>
<body>
  <button id="bleu" onclick="appuyez()">
  </button>
  <button id="vert" onclick="amusement()">
  </button>
  </body>
</html>

CSS

#bleu{
  width: 100px;
  height: 100px;
  background-color: blue;
}
#vert{
  margin-left: 50px;
  width: 100px;
  height: 100px;
  background-color: green;
}

JavaScript

function appuyez(){

let element = document.getElementById("bleu");

// Récupérez la couleur de fond
let backgroundColor = window.getComputedStyle(element).backgroundColor;


if(backgroundColor != "rgb(0, 0, 255)"){
alert("Quelqu'un a appuyé sur le carré qui n'est pas bleu !");
}
else{
window.alert("Quelqu'un a appuyé sur le carré bleu");
 }
 document.getElementById("bleu").style.background = "blue";
}
function amusement(){
document.getElementById("bleu").style.background = "#E6C7DE";

}