Skip to content

Instantly share code, notes, and snippets.

@refoerofekr
Last active June 29, 2023 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save refoerofekr/e81f8f66d61f82aeb2955cf0c0a1e0e7 to your computer and use it in GitHub Desktop.
Save refoerofekr/e81f8f66d61f82aeb2955cf0c0a1e0e7 to your computer and use it in GitHub Desktop.
scriptName.js
<script type="text/javascript">
let timer;
const timerDisplay = document.getElementById('seconds');
let actualCoef = 1;
document.getElementById('timerButton').addEventListener('click', startTimer);
// функция запуска таймера
function startTimer() {
let timerButton = document.getElementById('timerButton')
timerButton.style.opacity = '75%';
timerButton.setAttribute('disabled', '');
let gameCoef = Math.random()*5;
let seconds = 1000;
let bar_width = 100;
timerDisplay.textContent = seconds;
timer = setInterval(() => {
timerDisplay.style.color = '#fff';
document.getElementById('bar').style.display = 'block';
bar_width = bar_width-0.1;
seconds--;
document.getElementById('bar').style.width = bar_width + '%';
players.innerHTML = '1';
timerDisplay.textContent = (seconds/100).toFixed(2) + 's';
// когда таймер доходит до нуля
if (seconds === 0) {
console.log('test1')
clearInterval(timer);
console.log('test2')
timerDisplay.innerHTML = 'x1.00';
timerDisplay.style.color = '#8F7DE1';
let test = setInterval(function coefCounter(){
document.getElementById('bar').style.display = 'none';
actualCoef += 0.01;
timerDisplay.innerHTML = 'x' + actualCoef.toFixed(2);
console.log(gameCoef)
if (actualCoef > gameCoef){
clearInterval(test);
timerDisplay.innerHTML = 'x' + gameCoef.toFixed(2)
timerDisplay.style.color = '#FF004D';
timerButton.removeAttribute('disabled');
timerButton.style.opacity = '100%';
actualCoef = 1;}
if (gameCoef<1.01){
clearInterval(test);
timerDisplay.innerHTML = 'x1.00';
timerDisplay.style.color = '#FF004D';
timerButton.removeAttribute('disabled');
timerButton.style.opacity = '100%';
actualCoef = 1;}
}, 150)}
}, 10);}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment