div 50 * 50px, every second, changes coordinates (randomly), and when clicked (hit), div will enter an account
need JS code (without jQuery)

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> .block{ width: 50px; height: 50px; background: red; position: absolute; top: 0 left: 0; } h1{ text-align: center; } </style> </head> <body> <h1>Ваш счёт:</h1> <div class="block"></div> <script> </script> </body> </html> 

Closed due to the fact that off-topic participants are teran , freim , 0xdb , Enikeyschik , LFC January 31 at 9:57 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • " Learning tasks are allowed as questions only on the condition that you tried to solve them yourself before asking a question . Please edit the question and indicate what caused you difficulties in solving the problem. For example, give the code you wrote, trying to solve the problem "- teran, freim, 0xdb, enikeyschik, LFC
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    need - duck write - teran
  • thank!!!!!!!! - Vetal Dudin
  • you are welcome. Check out the Help topic How to ask questions . This is not a homework service, take the trouble to start at least on your own, and when you run into a problem, ask a question. - teran

1 answer 1

 let result = 0; const resultElement = document.querySelector('h1'); const block = document.querySelector('.block'); const containerWidth = document.documentElement.clientWidth; const containerHeight = document.documentElement.clientHeight; const getRandomNumber = (min, max) => { return Math.round(min - 0.5 + Math.random() * (max - min + 1)); } setInterval(() => { block.style.left = getRandomNumber(0, containerWidth - block.offsetWidth) + 'px'; block.style.top = getRandomNumber(0, containerHeight - block.offsetHeight) + 'px'; }, 1000) block.addEventListener('click', () => { resultElement.textContent = `Ваш счёт: ${++result}`; }) 
 .block{ width: 50px; height: 50px; background: red; position: absolute; top: 0 left: 0; } h1{ text-align: center; } 
 <h1>Ваш счёт:</h1> <div class="block"></div>