Advertisement
thetenfold

Untitled

Aug 2nd, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5.  
  6. <meta charset="UTF-8">
  7. <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
  8.  
  9. <title>title</title>
  10.  
  11. <script type="text/javascript">
  12.  
  13. // there are 3 levels here. you can add more
  14. // by adding more integers to the array
  15. var levels = ['',
  16. 3,
  17. 3,
  18. 3
  19. ],
  20. level = 1, // store the level and increment it when the user finishes one
  21. time = levels[1], // time is set to the first level's time (10)
  22. t;
  23.  
  24. function cddisplay() {
  25. // displays time in span
  26. document.getElementById('timespan').innerHTML = 'Level: ' + level + '. ' + 'Time Left: ' + time;
  27. };
  28.  
  29. function countdown() {
  30. // starts countdown
  31. cddisplay();
  32.  
  33. if (time <= 0) {
  34. alert('Time\'s up for level ' + level);
  35.  
  36. level += 1;
  37. if (level >= levels.length) {
  38. // execute code if the user has finished all of the levels
  39. alert('You finished all ' + (levels.length - 1) + ' levels!');
  40. phoneui.gotoPage('m1-HOMESCREEN', 'NONE');
  41. location.reload();
  42. } else {
  43. time = levels[level];
  44. }
  45. } else {
  46. time -= 1;
  47. t = setTimeout(countdown, 1000);
  48. }
  49. };
  50.  
  51. function cdpause() {
  52. // pauses countdown
  53. clearTimeout(t);
  54. };
  55.  
  56. function cdreset() {
  57. // resets countdown
  58. cdpause();
  59. time = levels[1];
  60. level = 1;
  61. cddisplay();
  62. };
  63.  
  64. </script>
  65.  
  66. <style type="text/css">
  67.  
  68. body {
  69. background-color: #EEEEEE;
  70. margin: 0;
  71. }
  72.  
  73. </style>
  74.  
  75. </head>
  76.  
  77. <body>
  78.  
  79. <span id="timespan">Level: 1. Time Left: x</span>
  80. <input type="button" value="Start" onclick="countdown()">
  81. <input type="button" value="Stop" onclick="cdpause()">
  82. <input type="button" value="Reset" onclick="cdreset()">
  83.  
  84. </body>
  85.  
  86. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement