Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="root">
  <p class="display" id="score">Le score est: 0 - 0</p>
  <div class="buttons">
    <div class="buttons-row">
      <button class="button" id="player-1">Point Joueur 1</button>
      <button class="button" id="player-2">Point Joueur 2</button>
    </div>
    <div class="buttons-row">
      <button class="button" id="reset">Remettre à zéro</button>
      <button class="button" id="pause">Pause / Reprendre</button>
    </div>
  </div>
</div>
              
            
!

CSS

              
                html {
  font-size: 16px;
  font-family: "Ubuntu", sans-serif;
}

body {
  margin: 0;
}

* {
  box-sizing: border-box;
}

#root {
  padding: 2rem;
  text-align: center;
  flex-direction: column;
  display: flex;
  align-items: stretch;
  justify-content: center;
  min-height: 100vh;
  max-width: 500px;
  margin: 0 auto;
}

p {
  margin: 0;
}

.buttons {
  align-self: center;
  display: flex;
  flex-direction: column;
}

.buttons-row {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.button {
  font-family: "Ubuntu", sans-serif;
  margin: 0.5rem;
  line-height: 1;
  border: none;
  padding: 0.8rem 1rem;
  font-size: 1rem;
  background: #232536;
  border-radius: 0.3rem;
  color: white;
  font-weight: 300;
  width: 170px;
  cursor: pointer;
}
.button:hover {
  background: #2c2f44;
}
.button:active {
  background: #1e212e;
}

.display {
  font-size: 2rem;
  font-weight: 700;
  padding: 1rem;
  background-color: #2759f5;
  color: white;
  border-radius: 0.3rem;
  line-height: 1.5;
  margin: 0;
  margin-bottom: 1rem;
}

.player-score {
  font-size: 1.4rem;
  font-weight: 400;
  padding: 0.5rem 1rem;
  margin-bottom: 1rem;
  background-color: #193ba1;
  color: white;
  border-radius: 0.3rem;
  line-height: 1.5;
  display: flex;
  justify-content: space-between;
}

.player-games {
  font-size: 1.4rem;
  font-weight: 400;
  padding: 0.5rem 1rem;
  margin-bottom: 1rem;
  background-color: #ae2b2b;
  color: white;
  border-radius: 0.3rem;
  line-height: 1.5;
  display: flex;
  justify-content: space-between;
}

              
            
!

JS

              
                // on trouve les éléments dans le document HTML
const score = document.getElementById("score");
const player1Button = document.getElementById("player-1");
const player2Button = document.getElementById("player-2");
const resetButton = document.getElementById("reset");
const pauseButton = document.getElementById("pause");

player1Button.addEventListener("click", () => {
  // Ce code s'exécute lorsque le bouton "Point Joueur 1" est cliqué
});

player2Button.addEventListener("click", () => {
  // Ce code s'exécute lorsque le bouton "Point Joueur 2" est cliqué
});

resetButton.addEventListener("click", () => {
  // Ce code s'exécute lorsque le bouton "Remettre à zéro" est cliqué
});

pauseButton.addEventListener("click", function () {
  // Ce code s'exécute lorsque le bouton "Pause / Reprendre" est cliqué
});

/**
 * Met à jour le text qui affiche le score
 * @param {boolean} playing
 * @param {'player1' | 'player2'} winner
 * @param {number} player1Score
 * @param {number} player2Score
 * @param {'player1' | 'player2'} advantage
 */
function updateScoreText(
  playing,
  winner = null,
  player1Score = 0,
  player2Score = 0,
  advantage = null
) {
  if (winner) {
    if (winner === "player1") {
      score.innerHTML = "Joueur 1 gagne";
    } else {
      score.innerHTML = "Joueur 2 gagne";
    }
  } else if (playing === false) {
    score.innerHTML = "C'est la pause";
  } else {
    let text = "Le score est: " + player1Score + " - " + player2Score;
    if (advantage) {
      if (advantage === "player1") {
        text += " avantage joueur 1";
      } else {
        text += " avantage joueur 2";
      }
    }
    score.innerHTML = text;
  }
}

// A vous de jouer !

              
            
!
999px

Console