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

              
                section.game
	.game__inner.container 
		.screen 
			h1.screen__headline Aim Training

			h3.screen__subheading
				span.warn Attention! &nbsp
				| If you don't hit the ball, you will lose

			button.screen__start Start

		.screen
			h1.screen__headline Choise time
			ul.time__list
				li.time__item
					button.time__btn(data-time='10') 10 Sec

				li.time__item
					button.time__btn(data-time='20') 20 Sec

				li.time__item
					button.time__btn(data-time='30') 30 Sec

				li.time__item.field
					input.time__field(type='number' placeholder='Another... (In seconds)')
					button.time__field-btn(type='submit')
		.screen
			h3.screen__title Time left &nbsp
				span.screen__timer 00:00

			.screen__board 
			.game-over.hide 
				button.game-over__restart Restart
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Comfortaa:wght@400;500;700&display=swap');

$black:          #000;
$white:          #fff;
$almostWhite:    #CFD8DC;

$primary:        #F57C00;
$primaryLight:   #ffa726;

$secondary:      #9142e0;
$secondaryLight: #c49aef;

* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

body {
	height: 100vh;
	margin: 0;
	overflow: hidden;

	color: $white;
	font-family: 'Comfortaa', sans-serif;
	text-align: center;

	background: #1b1c22;

}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}

button {
	color: inherit;

	border: none;

	cursor: pointer;
}

.container {
	position: relative;

	width: 100vw;
	height: 100vh;
	overflow: hidden;
}

.screen {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	width: 100vw;
	height: 100vh;

	transition: margin 0.5s ease-out;

	&.up {
		margin-top: -100vh;
	}

	&__headline {
		margin-bottom: 20px;

		font-size: 64px;
	}

	&__subheading {
		margin-bottom: 50px;

		color: $primaryLight;
	}

	&__start {
		padding: 10px 30px;

		font-size: 24px;

		background: none;
		border-radius: 5px;

		transition: 0.5s;
	}

	&__board {
		position: relative;

		display: flex;
		align-items: center;
		justify-content: center;
		width: 500px;
		height: 500px;
		overflow: hidden;

		background: none;
		border-radius: 30px;

		transition: .5s;
	}

	&__title {
		font-size: 24px;
		margin-bottom: 30px;
	}

	&__timer {
		color: $secondary;
	}
}

.time {
	&__list {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		gap: 20px;
		padding: 0;

		list-style: none;
	}

	&__item {
		display: flex;

		color: $white;

		border: 2px solid $almostWhite;
		border-radius: 5px;

		transition: .2s;

		&:not(:last-child):hover {
			color: $secondary;

			border: 2px solid $secondary;
		}
	}

	&__btn {
		padding: 0.5rem 1rem;

		font-family: inherit;
		font-size: 1.5rem;

		background-color: transparent;
		border-radius: 5px;

		cursor: pointer;

		&:hover {
			color: $secondary;

			transition: .1s;
		}
	}

	&__field {
		display: flex;
		padding: 0.5rem 1rem;

		color: $white;
		font-family: inherit;
		font-size: 1.5rem;

		background-color: transparent;
		border: none;
		border-radius: 5px 0 0 5px;

		cursor: pointer;

		&:focus {
			outline: none;
		}

		&::placeholder {
			font-size: 22px;
		}

		&-btn {
			position: relative;

			width: 30px;

			background: $almostWhite;
			border-radius: 0 2px 2px 0;

			transition: .2s;

			&:before {
				position: absolute;
				top: 50%;
				left: 30%;

				width: 10px;
				height: 2px;
				background: #fff;
				border-radius: 2px;

				content: '';
			}

			&::after {
				position: absolute;
				top: 50%;
				left: 30%;

				width: 10px;
				height: 2px;

				transform: rotate(90deg);
				background: #fff;
				border-radius: 2px;

				content: '';
			}

			&:hover {
				background: $secondary;
				&:before, &:after {
					background: $white;
				}
			}
		}
	}
}


.hide {
	opacity: 0;
	visibility: hidden;

	pointer-events: none;
}

.primary {
	color: $secondary;
}

.circle {
	position: absolute;

	background: $secondaryLight;
	border-radius: 50%;

	transition: .5s;

	cursor: pointer;
}

.warn {
	color: $primary;
}

.game-over {
	position: absolute;

	display: flex;
	flex-direction: column;

	&__message {
		display: flex;
		flex-direction: column;
		margin-bottom: 50px;

		color: $primaryLight;
		font-size: 24px;

		& > span {
			margin-bottom: 5px;

			color: $primary;
			font-size: 28px;
		}

		& p {
			&:not(:last-child) {
				margin-bottom: 15px;
			}

			& > span {
				color: $secondary;
			}
		}
	}

	&__restart {
		margin-top: 300px;
		padding: 10px 30px;

		font-size: 24px;
		background: none;
		border-radius: 5px;

		transition: 0.5s;
	}
}
              
            
!

JS

              
                const screen     = document.querySelectorAll('.screen');
const btnStart   = document.querySelector('.screen__start');
const restart    = document.querySelector('.game-over');
const btnReStart = document.querySelector('.game-over__restart');
const timeList   = document.querySelector('.time__list');
const field      = document.querySelector('.field');
const timer      = document.querySelector('.screen__timer');
const hasFocus   = document.querySelector('.time__field');
const btnTime    = document.querySelector('.time__field-btn');
const board      = document.querySelector('.screen__board');
const circle     = document.querySelector('.circle');

// Counter(-Stricke :3)
let time = 0;
let score = 0;

let inputValue;
let isOver = false;
let inter;
let interInput;

// Func / Start
// Set time
const setTime = (value) => {
	timer.innerHTML = value;
}

// Get random number
const getRndNum = (min, max) => {
	return Math.round(Math.random() * (max - min) + min);
}

// Get random HEX color
const getRndColor = () => {
	const rndColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
	return rndColor;
};

// Get value from input
const getInputValue = () => {
	const value = document.querySelector('.time__field').value;

	if (value !== 0 && value.length > 0) {
		inputValue = value;
		screen[1].classList.add('up');
	}
}

// Decrease time (Buttons)
const decTime = () => {
	if (time === 0) {
		gameEnd();

	} else if (isOver === true) {
		board.innerHTML = ''
		restart.classList.remove('hide');
		gameOver();

	} else {
		let current = --time
		if (current < 10) {
		  current = `0${current}`
		}
		setTime(`00:${current}`)
	}
};

// Decrease time (Input)
const decTimeInput = () => {
	if (inputValue === 0) {
		gameEnd();
	} else if (isOver === true) {
		board.innerHTML = ''
		restart.classList.remove('hide');
		gameOver();

	} else {
		let value = --inputValue;

		const seconds = value % 60;
		const secondsInMinutes = (value - seconds) / 60;
		const minutes = secondsInMinutes % 60;
		const hours = (secondsInMinutes - minutes) / 60;

		let current = `${hours}:${minutes}:${seconds}`;

		if (hours < 10 && hours !== 0) {
			current = `0${hours}:${minutes}:${seconds}`;

		} else if (hours === 0 && minutes > 10) {
			current = `${minutes}:${seconds}`;

		} else if (minutes < 10 && seconds > 10) {
			current = `0${minutes}:${seconds}`;

		} else if (seconds < 10) {
			current = `0${minutes}:0${seconds}`;
		}

		setTime(current);
	}
}

// Create circle on a board
const createRndCircle = () => {
	const circle = document.createElement('div');
	circle.classList.add('circle');

	// Sets dynamic random size and background color
	setInterval(() => {
		const { width, height } = board.getBoundingClientRect();
		const s = getRndNum(10, 60);
		const x = getRndNum(0, width - s);
		const y = getRndNum(0, height - s);

		circle.style.width = `${s}px`;
		circle.style.height = `${s}px`;
		circle.style.top = `${x}px`;
		circle.style.left = `${y}px`;
		circle.style.background = getRndColor();
	}, 1000);

	board.append(circle);
}

// Sets the params when starting the game. (Buttons)
const gameStart = () => {
	timer.innerHTML = '00:00';
	timer.parentElement.classList.remove('hide');
	board.innerHTML = '';
	isOver = false;
	inter = setInterval(decTime, 1000);
	createRndCircle();
}

// Sets the params when starting the game. (Input)
const gameStartInput = () => {
	timer.innerHTML = '00:00';
	timer.parentElement.classList.remove('hide');
	board.innerHTML = '';
	isOver = false;
	interInput = setInterval(decTimeInput, 1000);
	createRndCircle();
}

// Sets the params when ending the game.
const gameEnd = () => {
	timer.parentElement.classList.add('hide');
	board.innerHTML = `<h1>Cчёт <span class='primary'>${score}</span></h1>`;
}

// Sets the params if the game over
const gameOver = () => {
	timer.parentElement.classList.add('hide');
	board.innerHTML = `<h3 class='game-over__message'>
							<span>Fail (ノಠ益ಠ)ノ彡┻━┻</span>
							<p>You lose :(<p>
							<p>Your count: <span>${score}</span></p>
						</h3>`
	clearInterval(inter);
	clearInterval(interInput);
}

// Sets dynamic color and box shadow
setInterval(() => {
	btnStart.style.color = getRndColor();
	btnStart.style.boxShadow = `0px 0px 30px -5px ${getRndColor()}`;
	btnReStart.style.color = getRndColor();
	btnReStart.style.boxShadow = `0px 0px 30px -5px ${getRndColor()}`;
	board.style.boxShadow = `0px 0px 20px -5px ${getRndColor()}`;
}, 100);
// Func / End

// Listeners / Start
btnTime.addEventListener('click', () => {
	getInputValue();
	gameStartInput();
});

btnStart.addEventListener('click', () => screen[0].classList.add('up'));

btnReStart.addEventListener('click', () => {
	screen[1].classList.remove('up');
	restart.classList.add('hide');
});

board.addEventListener('click', (e) => {
	if (e.target.classList.contains('circle')) {
		score++;
		e.target.remove();
		createRndCircle();
	} else {
		isOver = true;
	}
})

timeList.addEventListener('click', (e) => {
	if (e.target.classList.contains('time__btn')) {
		time = parseInt(e.target.getAttribute('data-time'));
		screen[1].classList.add('up');
		gameStart();
	}
});

hasFocus.addEventListener('focusin', () => {
	field.style.border = '2px solid #9142e0';
	btnTime.style.background = '#9142e0';
})

hasFocus.addEventListener('focusout', () => {
	field.style.border = '2px solid #CFD8DC';
	btnTime.style.background = '#CFD8DC';
})
// Listeners / End
              
            
!
999px

Console