Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. "use strict";
  2.  
  3. function jeuPendu() {
  4. let mots = ["poule", "technologie", "magasin", "ordinateur", "carnet", "microscope", "ananas", "chevalier", "melancolie", "sapin", "bracelet", "herisson", "dinosaure", "programme", "oreiller"];
  5. let random = Math.round(Math.random() * mots.length);
  6. let secret = mots[random];
  7. let trema = "_ ";
  8. let found = 0;
  9. let lettre;
  10. let i;
  11. let affichage;
  12. let newaffichage;
  13.  
  14.  
  15.  
  16. console.log("Bienvenue au jeu du pendu, tentez de retrouver mon mot secret !");
  17. affichage = trema.repeat(secret.length);
  18. console.log(affichage);
  19.  
  20. while ( found < secret.length) {
  21. lettre = prompt("Entrez une lettre");
  22. for ( i = 0; i < secret.length; i++) {
  23. if (secret[i] === lettre) {
  24. newaffichage = affichage.replace(affichage[i-1], secret[i]);
  25. found = found++;
  26. console.log(newaffichage);
  27. }
  28. }
  29. }
  30.  
  31.  
  32. }
  33. console.log(jeuPendu());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement