title: the javascript code doesn't work as expected need some help details are put in the body
body: <p>I've made a game code</p>
  <p>the game starts when clicking on start game button :fruits start dropping and when you hover on the the dropping fruit it explodes and score increases by +1.</p>
  <p>when you miss 3 fruits the game over div appears and with your score, by clicking on start button again a new game starts.</p>
  <p>the game works fine but i decided to add on it more thing i wanted to make it a little challengable so I added an if condition to make the fruit run with a fixed speed and run faster after  each time the score increases by 5 points the function which increases the speed is called difficulty()</p>
  <p>it worked well at the first time but after game over div appears and clicking on start game button  it doesn't work well with the dropping speed of fruits what is the problem??</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var gameon = false
  var x 
  var y
  var t
  var num
  var remaininglives
  var step
  var score
  
  $("#startreset").click(
  function(){
      if(gameon==true){
          location.reload();
      }
      else{
          gameon = true;
          $(this).text("Restart Game");
          $("#gameover").hide();
          remaininglives=4;
          score = 0;
          t=100;
          $("#score").html(score);
          lives();
          makefruit(); 
          startaction();
          
         $("#fruit1").mouseover(function(){
              score++;
              $("#score").html(score); 
              clearInterval(action);
              //document.getElementById("slicesound").play();
              $("#slicesound")[0].play()
              $("#fruit1").hide("explode",500); 
             difficulty(t);
              setTimeout(function(){ makefruit(); startaction();}, 800);
  });
                  
      }
          
      
  }
  )
  
  function lives(){
              for(i=1;i&lt;remaininglives;i++){
                  
                  $("#lives").append("&lt;img src = 'heart.png' width = 25px&gt;")
             }
      
          }
  
  
  
  function makefruit(){
          x = Math.round(Math.random()*580);
          step = 1+Math.round(Math.random()*10);
          num = 1+Math.round(Math.random()*5);
          $("#fruit1").attr("src","fruit"+num+".png")
          $("#fruit1").css({display:"inline",left:x+"px",top:"-25px"}); 
  }
  
  
  
  function startaction(){
      
         action = setInterval(function(){
             //$("#fruit1").css({top:$("#fruit1").position().top+step});
             $("#fruit1").css({top:$("#fruit1").position().top+10});
             
             if($("#fruit1").position().top &gt; $("#question").height()){
                 remaininglives--;
                 $("#lives").empty();
                 lives();
               if(remaininglives &gt; 1){
                   
                 makefruit();
                   
                  } 
                 else{
                     
                     $("#gameover").show();
                     $("#scores").html(score);
                     gameon = false;
                     $("#startreset").text("Start Game")
                     clearInterval(action);
                    
                 }
             }
         },t) }
   
  function difficulty(t){for(n=0;n&lt;50;n+=5){if(score==n){
       if(t!=20)
       {t=t-10}
   }} }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#container {
      height: 600px;
      width: 750px;
      background-color: #9DD2EA;
      margin: 10px auto;
      padding: 20px;
      border-radius: 10px;
      box-shadow: 0px 4px 0px 0px #009de4;
      -moz-box-shadow: 0px 4px 0px 0px #009de4;
      -webkit-box-shadow: 0px 4px 0px 0px #009de4;
  /*        box-shadow: [horizontal offset] [vertical offset] [blur radius] [optional spread radius] [color]*/
      position: relative;
  }
  #scorebox {
  background-color: #F1FF92;
      color: #888E5F;
      padding: 11px;
      position: absolute;
      left: 700px;
      box-shadow: 0px 4px 0px #9da853;
      -moz-box-shadow: 0px 4px 0px #9da853;
      -webkit-box-shadow: 0px 4px 0px #9da853;
  }
  
  #correct {
      background-color:#42e252;
      color: white;
      padding: 5px;
      position: absolute;
      left:250px;
      top: 23px;
      display: none;
      
  }
  
  #tryagain {
       background-color:#de401a;
      color: white;
      padding: 5px;
      position: absolute;
      left:250px;
      top: 23px;
      display: none;
  }
  
  html {
      background: radial-gradient( circle,#fff,#ccc);
      height: 100%;
          
  }
  
  #question {
      width: 650px;
      height: 400px;
      margin: 50px auto 10px auto;
      background-color: white;
      box-shadow: 0px 4px #535aa8;
      -moz-box-shadow: 0px 4px #535aa8;
      -webkit-box-shadow: 0px 4px #535aa8;
      
      
      font-family: cursive, sans-serif;
      color: black;
      position: relative;
      overflow: hidden;
      
  }
  
  #instructions {
      width:450px;
      height:50px;
      background-color: #9DA0EA;
      box-shadow: 2px 4px #535aa8;
      margin:10px auto;
      font-family: cursive,sans-serif;
      line-height: 50px;
      text-align: center;
  
  }
  
  #fruit1{
      
     position: absolute;
      display: none;
  }
  
  #fruit2{
      
     position: absolute;
         display: none;
  }
  
  #fruit4{
      
     position: absolute;
      display: none;
  }
  
  #fruit3{
      
     position: absolute;
      display: none;
  }
  
  #fruit6{
      
     position: absolute;
      display: none;
  }
  
  
  #fruit5{
      
     position: absolute;
      display: none;
  }
  
  #lives{
      width: 80px;
      padding: 10px;
      position: absolute;
      background-color: #F1FF92;
      border-radius: 3px;
      box-shadow: 0px 4px rgba(0, 0, 0, 0.2);
      -moz-box-shadow: 0px 4px rgba(0, 0, 0, 0.2);
      -webkit-box-shadow: 0px 4px rgba(0, 0, 0, 0.2);
  /*    visibility: hidden;*/
     /* display: none;*/
  }
  
  
  
  #choices {
      width: 450px;
      height: 100px;
      margin:5px auto 0px auto;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
  }
  
  .box {
      width: 85px;
      height: 85px;
      background-color: aliceblue;
      color: #9DA0EA;
      font-size: 30px;
      text-align: center;
      line-height: 85px;
      border-radius: 100px;
      margin: 10px 0px; 
      cursor: pointer;
      box-shadow: 0px 4px;
      position: relative;
      
  }
  
  .box:hover, #startreset:hover{
      background-color: #9C89F6;
      color: white;
      box-shadow: 0px 4px #6b54d3;
      -moz-box-shadow: 0px 4px #6b54d3;
     -webkit-box-shadow: 0px 4px #6b54d3;
  }
  
  .box:active, #startreset:active{
      background-color: #9C89F6;
      color: white;
      box-shadow: 0px 0px #6b54d3; 
      -moz-box-shadow: 0px 0px #6b54d3; 
      -webkit-box-shadow: 0px 0px #6b54d3; 
      top: 4px;
  }
  
  #startreset{
      width: 100px;
      background-color: rgba( 255, 180, 5, 0.963 );
      color: black;
      text-align: center;
      padding: 5px;
      margin: 8px auto 0px auto; 
      cursor: pointer;
      box-shadow: 2px 4px rgba( 0,0 ,0 , 0.3 ) ;
      position: relative;
  }
  #timeremaining {
      width: 170px;
      background-color:rgba(181, 235, 36, 0.8);
      padding: 4px;
      position: absolute;
      right: 20px;
      bottom:15px;
      box-shadow:2px 4px rgba( 105, 211, 99, 0.652 ) ;
  }
  
  #gameover{
      height: 200px;
      width: 500px;
      background: linear-gradient(#F3CA6B, #F3706C);
      background: -webkit-linear-gradient(#F3CA6B, #F3706C);
      background: -o-linear-gradient(#F3CA6B, #F3706C);
      background: -moz-linear-gradient(#F3CA6B, #F3706C);
      color: white;
      font-size: 2.5em;
      text-align: center;
      text-transform: uppercase;
      position: absolute;
      top: 170px;
      left: 145px;
      z-index: 2;
      
      display: none;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;fruit slice game&lt;/title&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" &gt;
      &lt;link rel="stylesheet" href="style.css"&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"&gt;&lt;/script&gt;
      
      
  &lt;link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
  
      
      
      
  &lt;body&gt;
      &lt;div id="container"&gt;
          
          &lt;div id="scorebox"&gt;
          Score:&lt;span id="score"&gt;0&lt;/span&gt;
          &lt;/div&gt;    
          
          
          
          &lt;div id="lives"&gt;
            
          &lt;/div&gt;
         
          
          
          
          &lt;div id="question"&gt;
              &lt;img width= 60px id="fruit1"&gt;
           
          
          &lt;/div&gt;
          
          
          &lt;div id="instructions"&gt;
          Catch The damn fruits!!!
          &lt;/div&gt;
          
          
          
          
          &lt;div id="startreset"&gt;
                  Start Game
          &lt;/div&gt;
              
           
              
          &lt;div id="gameover"&gt;
              &lt;p&gt;GAME OVER&lt;/p&gt;
             &lt;p&gt; Your score is &lt;span id="scores"&gt;0&lt;/span&gt; &lt;/p&gt;  
          &lt;/div&gt;
          
          &lt;script src="javascript.js"&gt;&lt;/script&gt;
          &lt;audio id="slicesound"&gt;
              &lt;source src="slicesound.mp3"&gt;
              &lt;source src="slicesound.ogg"&gt;
          &lt;/audio&gt;
          
      &lt;/div&gt;    
      &lt;/body&gt;    
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  <p><a href="https://drive.google.com/file/d/1DpX22ighGaDOX6I7UrXtZfSzJj1oRaqG/view?usp=sharing" rel="nofollow noreferrer">images used in the game can be downloaded from this google drive link </a></p>