0

I want the page to reload (the game to restart) 2 seconds after the user views his/her score. Also, is it possible to set minimum and maximum height for the shape that appears.

const start = new Date();
const x = Math.floor(Math.random() * 256);
const y = Math.floor(Math.random() * 256);
const z = Math.floor(Math.random() * 256);
const bgColor = "rgb(" + x + "," + y + "," + z + ")";
const shape = document.querySelector("#shape");

const generateShape = () => {
const shape = document.querySelector("#shape");
shape.style.height = Math.floor(Math.random() * 250) + "px";
shape.style.width = Math.floor(Math.random() * 250) + "px";
shape.style.borderRadius = Math.floor(Math.random() * 100) + "%";
shape.style.margin = Math.floor(Math.random() * 300) + "px";
shape.style.backgroundColor = bgColor;
}

const getTime = () => {
shape.style.display = "none";
const stop = new Date();
const timeDiff = stop.getTime() - start.getTime();
const writeTime = document.querySelector("#span");
writeTime.innerHTML = timeDiff / 1000 + " s"
}

shape.addEventListener("click", getTime);

generateShape();
  • 1
    To reload page: `window.location.reload()` – Jihlavanka Nov 30 '18 at 21:16
  • 1
    Possible duplicate of [How to automatically reload a page after a given period of inactivity](https://stackoverflow.com/questions/4644027/how-to-automatically-reload-a-page-after-a-given-period-of-inactivity) – devlin carnate Nov 30 '18 at 21:30

0 Answers0