Skip to content

Instantly share code, notes, and snippets.

@emidblol
Created April 4, 2026 08:48
Show Gist options
  • Select an option

  • Save emidblol/3c80c11d67b63e3bcedee10148083a1a to your computer and use it in GitHub Desktop.

Select an option

Save emidblol/3c80c11d67b63e3bcedee10148083a1a to your computer and use it in GitHub Desktop.
Scoreboard
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Rubik" rel="stylesheet">
<div>
<header>
<h1 class="text-center">Scoreboard</h1>
</header>
<div class="scorecontainer">
<div class="btncontainer">
<h2>Home</h2>
<div class="btn" id="team1">0</div>
<button class="scorebtn" id="homeplus">+</button>
<button class="scorebtn" id="homeminus">-</button>
</div>
<div id="roundcounter">
<button id="roundplus">+</button>
<div id="rounddisplay">
<p>Round</p>
<p id="roundnum">0<p>
</div>
<button id="roundminus">-</button>
</div>
<div class="btncontainer">
<h2>Away</h2>
<div class="btn" id="team2">0</div>
<button class="scorebtn" id="awayplus">+</button>
<button class="scorebtn" id="awayminus">-</button>
</div>
</div>
</div>
const scoreBoard = {
_round: 0,
_home: 0,
_away: 0,
range: [0, 99],
set home(val) {
this._home = val;
document.querySelector('#team1').textContent = this._home;
},
set away(val) {
this._away = val;
document.querySelector('#team2').textContent = this._away;
},
set round(val) {
this._round = val;
document.querySelector('#roundnum').textContent = this._round;
},
checkRangeAndUpdate(value, operator, step) {
// destructure max and min
const [min, max] = this.range;
// set getter to underscore value for accessing object
const getter = `_${value}`;
if(operator === '+' && (this[getter] + step) - 1 < max) {
// if operator is add and the incrementation wont exceede max increment by step
this[value] = this[getter] + step;
}
if(operator === '-' && (this[getter] - step) + 1 > min) {
// if operator is sub and the decrementation wont go below min deincrement by step
this[value] = this[getter] - step;
}
},
 homeplus: ['home', '+', 1],
 homeminus: ['home', '-', 1],
 awayplus: ['away', '+', 1],
 awayminus: ['away', '-', 1],
 roundplus: ['round', '+', 1],
 roundminus: ['round', '-', 1]
}
function init() {
 const container = document.querySelector('.scorecontainer');
 container.addEventListener('click', function(e) {
// run function with params that match the buttons id
   scoreBoard.checkRangeAndUpdate.apply(scoreBoard, scoreBoard[e.target.id]);
 });
}
init();
// OLD CODE
// var round = 0, homeScore = 0, awayScore = 0;
// $('document').ready(function() {
// $('#homeplus').click(function() {
// if (homeScore < 100) {
// homeScore += 1;
// $('#team1').text(homeScore);
// }
// });
// $('#homeminus').click(function() {
// if (homeScore > 0) {
// homeScore -= 1;
// $('#team1').text(homeScore);
// }
// });
// $('#roundminus').click(function() {
// if (round > 0) {
// round -= 1;
// $('#roundnum').text(round);
// }
// });
// $('#roundplus').click(function() {
// if (round < 1000) {
// round += 5;
// $('#roundnum').text(round);
// }
// });
// $('#awayplus').click(function() {
// if (awayScore < 100) {
// awayScore += 1;
// $('#team2').text(awayScore);
// }
// });
// $('#awayminus').click(function() {
// if (awayScore > 0) {
// awayScore -= 1;
// $('#team2').text(awayScore);
// }
// });
// });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
.jumbotron {
background-color: transparent;
}
#app {
min-width: 247px;
}
.wrapper {
display: flex;
align-items: center;
justify-content: center;
}
body {
background-color: #90b9f9;
}
header {
background-color: #4385ef;
padding: 10px 90px 15px 90px;
border-radius: 15px;
color: #2c4b7c;
width: 613px;
margin: 0 auto;
margin-top: -20px;
margin-bottom: 2em;
box-shadow: inset 0px -5px 1px #234d8e, 6px 7px 3px rgba(66, 66, 66, 0.5);
& h1 {
font-family: rubik;
font-weight: 800;
user-select: none;
text-shadow: 2px 2px 2px;
}
}
.scorecontainer {
display: flex;
align-items: center;
justify-content: center;
height: 40em;
width: 80%;
margin-left: 10%;
background-color: #4385ef;
padding: 10px 90px 15px 90px;
border-radius: 10px;
position: absolute;
z-index: -10;
box-shadow: inset 0px -5px 1px #234d8e, 6px 7px 3px rgba(66, 66, 66, 0.5);
}
.btn {
width: 300px;
margin-top: 0px;
cursor: default;
height: 300px;
border: 0;
border-radius: 20px;
outline: none !important;
font-size: 200px;
font-family: rubik;
text-shadow: 3px 3px 5px;
display: block;
position: relative;
z-index: 5;
top: 15px;
}
#team1 {
background-color: #e85c5c;
box-shadow: inset 0 -5px 1px #842f2f, 6px 7px 3px rgba(66, 66, 66, 0.5);
}
#team2 {
background-color: #60e85c;
box-shadow: inset 0 -5px 1px #37842f, 6px 7px 3px rgba(66, 66, 66, 0.5);
}
.btncontainer {
display: inline-block;
margin: 0 45px 20px 45px;
text-align: center;
& h2 {
font-family: rubik;
font-size: 30px;
background-color: #f7ff66;
color: #383838;
border-radius: 10px;
font-weight: 800;
padding: 10px 15px 15px 15px;
box-shadow: inset 0 -5px 1px #5a5e11, 6px 7px 3px rgba(66, 66, 66, 0.5);
}
}
.scorebtn {
background-color: #5e5e5e;
color: #ddd;
display: inline-block;
padding-top: 10px;
font-size: 45px;
border-radius: 10px;
box-shadow: inset 0 -4px 1px #383838, 4px 4px 3px rgba(66, 66, 66, 0.5);
border: 0;
top: -10px;
margin: 0px 10px 0px 10px;
width: 80px;
height: 80px;
transition: 0.5s;
&:active {
box-shadow: none;
}
&:focus {
outline: none;
}
}
#rounddisplay {
background-color: #383838;
text-align: center;
border-radius: 10px;
width: 70px;
padding: 15px 10px 10px 10px;
& p {
color: #ddd;
font-family: rubik;
&:nth-child(1) {}
&:nth-child(2) {
font-size: 50px;
}
}
}
#roundcounter {
border-radius: 5px;
margin-bottom: 35px;
}
#roundplus,
#roundminus {
background-color: #383838;
margin: 0 auto;
border-radius: 5px;
text-align: center;
font-size: 30px;
height: 50px;
color: #ddd;
width: 100%;
border: none;
transition: 0.5s;
&:focus {
outline: none;
}
& span {
transition: 0.5s;
}
}
#roundplus {
margin-bottom: -20px;
width: 70px;
border-bottom-left-radius: 0;
border-bottom: 10px #383838 solid;
border-bottom-right-radius: 0;
}
#roundminus {
margin-top: -15px;
width: 70px;
box-shadow: inset 0px -4px 1px #232323;
&:active {
box-shadow: none;
}
}
@media (max-width: 1030px) {
.btn {
width: 250px;
height: 250px;
font-size: 170px;
}
#roundcounter {
width: 60px;
}
.btncontainer {
margin: 0 30px -30px 30px;
height: 480px;
}
.scorecontainer {
height: 470px;
}
}
@media (max-width: 850px) {
.btn {
width: 230px;
height: 230px;
font-size: 150px;
}
.btncontainer {
display: block;
margin-bottom: -20px;
margin-left: 20px;
margin-right: 15px;
}
.scorecontainer {
width: 90%;
margin-left: 5%;
height: 470px;
}
}
@media (max-width:655px) {
.btn {
height: 210px;
width: 210px;
font-size: 140px;
}
header {
width: 80%;
}
.btncontainer {
height: 400px;
margin-top: 10px;
}
.scorecontainer {
height: auto;
}
}
@media (max-width:585px) {
header {
width: 90%;
margin-top: -10px;
padding: 1px 0 10px 0px;
margin-bottom: 15px;
& h1 {
margin-top: 20px;
}
}
.scorecontainer {
flex-direction: column;
align-items: right;
height: auto;
}
.btn {
width: 300px;
}
.btncontainer {
display: inline-block;
width: auto;
margin: 0;
height: 440px;
}
#roundcounter {
display: flex;
border-radius: 0;
width: 303px !important;
margin: 0;
}
#roundplus,
#roundminus {
margin: 0;
height: 80px;
border-radius: 0;
box-shadow: none;
transition: 0s;
width: 1000px !important;
}
#roundplus {
border-top-left-radius: 8px;
border-bottom-left-radius: 8px;
border: 0;
}
#roundminus {
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
}
#rounddisplay {
height: 80px;
padding: 5px;
margin: 0;
border-radius: 0;
& p {
color: #ddd;
font-family: rubik;
&:nth-child(1) {
margin: 0;
display: block;
}
&:nth-child(2) {
font-size: 40px;
display: inline-block;
}
}
}
}
@media (max-width: 400px) {
header {
min-width: 276px;
margin-left: 18px;
}
.scorecontainer {
padding: 20px;
min-width: 276px;
}
.btncontainer {
width: 99%;
height: auto;
margin-bottom: 15px;
}
.btn {
width: 240px;
height: 220px;
margin: 0 auto;
font-size: 120px;
}
#roundcounter {
width: 90% !important;
}
}
@media (max-width: 320px) {
header {
margin: 0 auto;
margin-bottom: 10px;
margin-top: -10px;
& h1 {
font-size: 25px;
}
}
.scorecontainer {
margin: 0;
width: 100%;
}
.btn {
width: 200px;
height: 200px;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment