JSFiddle - React, Tailwind, and code Playground

by CollonilTolli

HTML

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

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="styles.css" />
    <title>Aim Training | Проект 5</title>
</head>

<body>
    <div class="screen">
        <h1>Aim Training</h1>
        <a href="#" class="start" id="start">Начать игру</a>
    </div>

    <div class="screen">
        <h1>Выберите время</h1>
        <ul class="time-list" id="time-list">
            <li>
                <button class="time-btn" data-time="10">
            10 сек
          </button>
            </li>
            <li>
                <button class="time-btn" data-time="20">
            20 сек
          </button>
            </li>
            <li>
                <button class="time-btn" data-time="30">
            30 сек
          </button>
            </li>
            <li>
                <button class="time-btn" data-time="60">
            60 сек
        </button>
            </li>
        </ul>
    </div>

    <div class="screen">
        <h3>Осталось <span id="time">00:00</span></h3>
        <div class="board" id="board"></div>
        <div class="btn-container hide">
            <a href="#" id="new-game">Новая игра</a>
        </div>

    </div>

    <script src="app.js"></script>
</body>

</html>

CSS

@import url('https://fonts.googleapis.com/css?family=Khula&display=swap');
* {
    box-sizing: border-box;
}

body {
    color: #fff;
    font-family: 'Khula', sans-serif;
    height: 100vh;
    overflow: hidden;
    margin: 0;
    text-align: center;
}

a {
    color: #fff;
    text-decoration: none;
}

a:hover {
    color: #16D9E3;
}

.start {
    font-size: 1.5rem;
}

h1 {
    line-height: 1.4;
    font-size: 4rem;
}

.screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
    transition: margin 0.5s ease-out;
    background: linear-gradient(90deg, #29323C 0%, #485563 100%);
}

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

.time-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    list-style: none;
    padding: 0;
}

.time-list li {
    margin: 10px;
}

.time-btn {
    background-color: transparent;
    border: 2px solid #C0C0C0;
    color: #fff;
    cursor: pointer;
    font-family: inherit;
    padding: .5rem 1rem;
    font-size: 1.5rem;
}

.time-btn:hover {
    border: 2px solid #16D9E3;
    color: #16D9E3;
}

.hide {
    opacity: 0;
}

.primary {
    color: #16D9E3;
}

.board {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    width: 400px;
    height: 400px;
    background: linear-gradient(118.38deg, #29323C -4.6%, #485563 200.44%);
    box-shadow: -8px -8px 20px #2A333D, 10px 7px 20px #475462;
    border-radius: 30px;
    overflow: hidden;
}

.circle {
    background: linear-gradient(90deg, #16D9E3 0%, #30C7EC 47%, #46AEF7 100%);
    position: absolute;
    border-radius: 50%;
    cursor: pointer;
}

.btn-container {
    background: linear-gradient( 118.38deg, #29323C -4.6%, #485563 200.44%);
    box-shadow: -8px -8px 20px #2a333d, 10px 7px 20px #475462;
    z-index: 100;
    padding: 5px 15px;
    border-radius: 0 0 5px 5px;
    transition: 1s ease;
    transition-delay: .5s;
}

JavaScript

const startBtn = document.querySelector('#start')
const newGameBtn = document.querySelector('#new-game')
const screens = document.querySelectorAll('.screen')
const timeList = document.querySelector('#time-list')
const timeEl = document.querySelector('#time')
const board = document.querySelector('#board')
const colors = ['#156B75', '#38D3D9', '#DEB7A2', '#A9263F', '#A228D9', '#7ED951']
let time = 0
let score = 0

startBtn.addEventListener('click', (event) => {
    event.preventDefault()
    screens[0].classList.add('up')
})

newGameBtn.addEventListener('click', (event) => {
    event.preventDefault()
    score = 0
    screens[1].classList.remove('up')
})

timeList.addEventListener('click', event => {
    if (event.target.classList.contains('time-btn')) {
        time = parseInt(event.target.getAttribute('data-time'))
        screens[1].classList.add('up')
        startGame()
    }
})

board.addEventListener('click', event => {
    if (event.target.classList.contains('circle')) {
        score++
        event.target.remove()
        createRandomCircle()
    }
})

function startGame() {
    board.innerHTML = ''
    newGameBtn.parentElement.classList.add('hide')
    timeEl.parentNode.classList.remove('hide')
    setInterval(decreaseTime, 1000)
    createRandomCircle()
    setTime(time)
}

function decreaseTime() {
    if (time === 0) {
        finishGame()
    } else {
        let current = --time
        if (current < 10) {
            current = `0${current}`
        }
        setTime(current)
    }
}

function setTime(value) {
    timeEl.innerHTML = `00:${value}`
}

function finishGame() {
    timeEl.parentNode.classList.add('hide')
    board.innerHTML = `<h1>Счет: <span class="primary">${score}</span></h1>`
    newGameBtn.parentElement.classList.remove('hide')
}


function createRandomCircle() {
    const circle = document.createElement('div')
    const size = getRandomNumber(10, 60)
    const { width, height } = board.getBoundingClientRect()
    const x =...