DEV Community

Cover image for Daily Code 74 | ๐Ÿ€ Basketball Score Board
Gregor Schafroth
Gregor Schafroth

Posted on

Daily Code 74 | ๐Ÿ€ Basketball Score Board

Alrigh after a bit of a break Iโ€™m back at coding!

Still working on the basics.

Today I did a small exercise where I made a basketball scoreboard with just html, css, and js.

(Please be aware that I donโ€™t actually know how basketball works, so excuse me if the board is wrong. I just followed the instructions haha)

My Code

Below is the code. If you run it anywhere it will work without the need for any additional files. ๐Ÿ™‚

<!DOCTYPE html>
<html lang="en">

  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Basketball Scoreboard</title>
  <link rel="preconnect" href="">
  <link rel="preconnect" href="" crossorigin>
    h1 {
      margin: 0;
      font-family: "Roboto", Arial, Helvetica, sans-serif;

    .score-board {
      display: flex;

    .team-container {
      border-style: solid;
      border-width: 1px;
      border-color: grey;
      border-radius: 10px;
      margin: 10px;
      padding: 10px;

    .guest-score {
      font-size: 55px;
      margin: 10px;
      text-align: center;

    .reset-button {
      margin: 10px;


  <div class="score-board">
    <div class="team-container">
      <p class="home-score" id="js-hs">0</p>
      <button id="js-h1">+1</button>
      <button id="js-h2">+2</button>
      <button id="js-h3">+3</button>
    <div class="team-container">
      <p class="guest-score" id="js-gs">0</p>
      <button id="js-g1">+1</button>
      <button id="js-g2">+2</button>
      <button id="js-g3">+3</button>
  <button class="reset-button" id="js-reset">RESET</button>

    let homeScore = 0;
    let guestScore = 0;

    document.getElementById("js-h1").addEventListener("click", homeOne);
    document.getElementById("js-h2").addEventListener("click", homeTwo);
    document.getElementById("js-h3").addEventListener("click", homeThree);
    document.getElementById("js-g1").addEventListener("click", guestOne);
    document.getElementById("js-g2").addEventListener("click", guestTwo);
    document.getElementById("js-g3").addEventListener("click", guestThree);

    function homeOne() {
      homeScore += 1;
      document.getElementById("js-hs").textContent = homeScore;

    function homeTwo() {
      homeScore += 2;
      document.getElementById("js-hs").textContent = homeScore;

    function homeThree() {
      homeScore += 3;
      document.getElementById("js-hs").textContent = homeScore;

    function guestOne() {
      guestScore += 1;
      document.getElementById("js-gs").textContent = guestScore;

    function guestTwo() {
      guestScore += 2;
      document.getElementById("js-gs").textContent = guestScore;

    function guestThree() {
      guestScore += 3;
      document.getElementById("js-gs").textContent = guestScore;

    document.getElementById("js-reset").addEventListener("click", resetScores)

    function resetScores() {
      homeScore = 0;
      guestScore = 0;
      document.getElementById("js-hs").textContent = homeScore;
      document.getElementById("js-gs").textContent = guestScore;


Enter fullscreen mode Exit fullscreen mode

Have a great day everyone!

Top comments (0)