countdown timer with cookies

this countdown does not resets when page reloads. This type of countdown can be used in games, quizzes or any mcq type of games or tests.

by globefire

HTML

<!DOCTYPE HTML>
<html>
<head>
    <title>Home</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body onload="checkCookie()"> 
<script>
  function setCookie(cname,cvalue,exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires=" + d.toGMTString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  }
  
  function getCookie(cname) {
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i < ca.length; i++) {
      var c = ca[i];
      while (c.charAt(0) == ' ') {
        c = c.substring(1);
      }
      if (c.indexOf(name) == 0) {
        return Number(c.substring(name.length, c.length));
      }
    }
    return "";
  }
  
  function checkCookie() {
    console.log("check cookie ke andar hu");
    var user=getCookie("countDownTime");
    console.log("get cookie ne ye return kia ", user);
    if (user > (new Date().getTime())) {
      var x = setInterval(function() {

        var now = new Date().getTime();
          
        var distance = user - now;
          
        var seconds = Math.floor((distance % (1000 * 60)) / 1000);
          
        document.body.innerHTML = '';
        document.write(seconds + "s");

        if (distance < 0) {
          clearInterval(x);
          document.body.innerHTML = "EXPIRED";
        }
      }, 1000);

    }
    else {  
      if(user < (new Date().getTime())){
        document.write("<br>tle, executing once again....");
        setTimeout(function(){return true;},3000);
        setCookie("countDownTime", (new Date().getTime()+60000), 30);
        checkCookie();  
      }
      else{
        document.write("<br>setting cookie for the first time.....");
        setTimeout(function(){return true;},3000);
        setCookie("countDownTime", (new Date().getTime()+60000), 30); 
        checkCookie();
      }
    }
  }
 ...