Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ add another resource


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


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.


Auto Save

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.


                <body class="wrapper l-stack-lg">
	<h1>Score Keeper</h1>

	<div class="l-stack-xxs">
		<label for="points-selector">Turns limit</label>
		<select id="points-selector">
			<option value="3">3</option>
			<option value="4">4</option>
			<option value="5">5</option>
			<option value="6">6</option>
			<option value="7">7</option>
			<option value="8">8</option>
			<option value="9">9</option>
			<option value="10">10</option>

	<div class="players-container">
		<div id="player1Container" class="l-stack-xs">
			<p id="player1Name" class="player-name player1">Player 1</p>
			<p id="player1Display" class="score">0</p>
			<button id="player1Btn" class="player-button player1">+ 1</button>

		<div id="player2Container" class="l-stack-xs">
			<p id="player2Name" class="player-name player2">Player 2</p>
			<p id="player2Display" class="score">0</p>
			<button id="player2Btn" class="player-button player2">+ 1</button>

	<p id="result" class="msg"></p>

	<button id="reset-game-btn">Restart game</button>


                /* This pen is using external base CSS stylesheet(s) in the CSS Settings */

:root {
	--page-max-inline-size: 40rem;

	--c-player1: hsl(220deg 100% 55%);
	--c-player1-darker: hsl(220deg 100% 45%);
	--c-player2: hsl(344deg 100% 45%);
	--c-player2-darker: hsl(344deg 100% 35%);
	--c-on-player: hsl(0deg 0% 100%);

@media (prefers-color-scheme: dark) {
	--c-player1: hsl(220deg 100% 65%);
	--c-player1-darker: hsl(220deg 100% 55%);
	--c-player2: hsl(344deg 100% 55%);
	--c-player2-darker: hsl(344deg 100% 45%);
	--c-on-player: hsl(0deg 0% 100%);

* {
	margin: 0;

body {
	padding-block: var(--padding-md);
	text-align: center;

button {
	align-self: center;

.players-container {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	row-gap: var(--spacing, 1rem);
	column-gap: var(--s-600);

.players-container > * {
	flex: 1;

.msg {
	font-size: var(--s-600);
	font-weight: var(--fw-700);

.msg:empty {
	display: none;

.score {
	padding: var(--padding-xxs);
	font-family: var(--ff-mono);
	font-size: 3rem;
	line-height: 1;
	text-align: center;
	background-color: var(--c-bg-2);
	border-radius: var(--border-radius);

.player1 {
	--c-player: var(--c-player1);
	--c-player-darker: var(--c-player1-darker);

.player2 {
	--c-player: var(--c-player2);
	--c-player-darker: var(--c-player2-darker);

.player-name {
	font-size: var(--s-600);
	line-height: var(--lh-small);
	font-weight: var(--fw-700);
	color: var(--c-player);

.player-button {
	display: block;
	inline-size: 100%;
	white-space: nowrap;
	color: var(--c-on-player);
	background-color: var(--c-player);
	border-color: var(--c-player);

.player-button:enabled:hover {
	background-color: var(--c-player-darker);
	border-color: var(--c-player-darker);

.msg [class*="player"] {
	color: var(--c-player);



                const pointsSelector = document.querySelector("#points-selector");
const resetGameBtn = document.querySelector("#reset-game-btn");
const result = document.querySelector("#result");

const player1 = {
	number: 1,
	name: document.querySelector("#player1Name").textContent,
	score: 0,
	display: document.querySelector("#player1Display"),
	button: document.querySelector("#player1Btn")

const player2 = {
	number: 2,
	name: document.querySelector("#player2Name").textContent,
	score: 0,
	display: document.querySelector("#player2Display"),
	button: document.querySelector("#player2Btn")

const players = [player1, player2];

let isGameOver = false;

for (const player of players) {
	player.button.addEventListener("click", function () {
		if (!isGameOver) {
			player.score += 1;
			player.display.textContent = player.score;
			if (player.score === parseInt(pointsSelector.value)) {
				isGameOver = true;
				players.forEach((player) => (player.button.disabled = true));
				pointsSelector.disabled = true;

pointsSelector.addEventListener("change", (e) => {

resetGameBtn.addEventListener("click", resetGame);

function resetScores() {
	for (const player of players) {
		player.score = 0;
		player.display.textContent = "0";

function resetGame() {
	isGameOver = false;
	result.textContent = "";
	players.forEach((player) => (player.button.disabled = false));
	pointsSelector.disabled = false;

function showTheWinner(player) {
	const resultWinner = document.createElement("span");
	resultWinner.textContent =;
	result.append("The winner is ", resultWinner, "!");