le html
<!DOCTYPE html>
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Bowlby+One&display=swap" rel="stylesheet">
<title>jeu du pendu</title>
</head>
<body>
<div id="plateau">
<h1 id="mot"></h1>
<h1>Proposer une lettre</h1>
</div>
</body>
<script src="script.js"></script>
</html>
le css
#plateau {
position: absolute;
width: 600px;
height: 300px;
top:50px;
left: 200px;
margin-top:50px;
background-color: aquamarine;
}
h1 {
color: #FF5733;
font-size: 30px;
width: 50%;
margin-left: 25%;
font-family: "Bowlby One", sans-serif;
font-weight: 400;
font-style: normal;
text-align: center;
}
le js
var liste_mots=["INFORMATIQUE","TENNIS","ORDINATEUR","LAPIN"]
var alea=Math.floor(Math.random() * 4);
var mot_a_trouver=liste_mots[alea];
var texte=document.getElementById("mot");
var mot_affiche="";
for ( var i=0;i<mot_a_trouver.length;i++){
mot_affiche=mot_affiche+"-";
}
texte.textContent=mot_affiche;
var tentatives=0;
document.addEventListener("keydown",touche,false);
function touche(evt){
var touche=event.key;
var lettre=touche.toUpperCase();
var retour=""
var lettre_dans_mot=false;
for ( var i=0;i<mot_a_trouver.length;i++){
if (lettre==mot_a_trouver[i]){
retour=retour+lettre;
lettre_dans_mot=true;
}
else {
retour=retour+mot_affiche[i];
}
}
if (lettre_dans_mot==false){
tentatives+=1;
document.getElementById("tentative").textContent="Tentatives : "+tentatives;
}
mot_affiche=retour;
texte.textContent=mot_affiche;
}