daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <title>Yay Vrijdag!</title>
  5.   <link rel="stylesheet" type="text/css" href="style.css">
  6.   <script type="text/javascript" src="jquery.js"></script>
  7. </head>
  8. <body>
  9.   <h1>Lets Race!</h1>
  10.   <div id="track">
  11.     <div class="car" id="car1"></div>
  12.     <div class="car" id="car2"></div>
  13.     <div class="car" id="car3"></div>
  14.     <div id="finish"></div>
  15.   </div>
  16.   <button id="start-button">GO!</button>
  17.   <script type="text/javascript" src="script.js"></script>
  18. </body>
  19. </html>
  20.  
  21.  
  22. $('#start-button').click(function(event) {
  23.   var pixelsToFinish = $(document).width() - 30 - 83;
  24.   var $car1 = $('#car1');
  25.   var $car2 = $('#car2');
  26.   var $car3 = $('#car3');
  27.  
  28.   var raceInterval = setInterval(function(){
  29.  
  30.     var randomLeftCar1 = Math.floor(Math.random() * 100) + 25;
  31.     var currentLeftCar1 = parseInt($car1.css('left'));
  32.     var newLeftCar1 = currentLeftCar1 + randomLeftCar1;
  33.     $car1.css({left:  newLeftCar1+'px'});
  34.  
  35.     var randomLeftCar2 = Math.floor(Math.random() * 100) + 25;
  36.     var currentLeftCar2 = parseInt($car2.css('left'));
  37.     var newLeftCar2 = currentLeftCar2 + randomLeftCar2;
  38.     $car2.css({left:  newLeftCar2+'px'});
  39.  
  40.     var randomLeftCar3 = Math.floor(Math.random() * 100) + 25;
  41.     var currentLeftCar3 = parseInt($car3.css('left'));
  42.     var newLeftCar3 = currentLeftCar3 + randomLeftCar3;
  43.     $car3.css({left:  newLeftCar3+'px'});
  44.  
  45.     if ((newLeftCar1 >= pixelsToFinish) || (newLeftCar2 >= pixelsToFinish)  || (newLeftCar3 >= pixelsToFinish)){
  46.  
  47.       if (newLeftCar1 >= pixelsToFinish) {
  48.         var pixelsRemaining = pixelsToFinish - currentLeftCar1;
  49.         var pixelsPerMilisecond = (randomLeftCar1 / 200);
  50.         console.log('CAR1:')
  51.         console.log(pixelsRemaining * pixelsPerMilisecond);
  52.       }
  53.       if (newLeftCar2 >= pixelsToFinish) {
  54.         var pixelsRemaining = pixelsToFinish - currentLeftCar1;
  55.         var pixelsPerMilisecond = (randomLeftCar2 / 200);
  56.         console.log('CAR2:')
  57.         console.log(pixelsRemaining * pixelsPerMilisecond);
  58.       }
  59.  
  60.       if (newLeftCar3 >= pixelsToFinish) {
  61.         var pixelsRemaining = pixelsToFinish - currentLeftCar1;
  62.         var pixelsPerMilisecond = (randomLeftCar3 / 200);
  63.         console.log('CAR3:')
  64.         console.log(pixelsRemaining * pixelsPerMilisecond);
  65.       }
  66.  
  67.       clearInterval(raceInterval);
  68.       return;
  69.     }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.   }, 200);
  80.  
  81.  
  82.  
  83.  
  84. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top