Advertisement
andrewb

Test Counter

Jun 17th, 2015
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.84 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>test on iphone</title>
  5. <script>
  6.  
  7. var Test = (function() {
  8.     function Test() {
  9.         this.counter = 0;
  10.         this.value = 1;
  11.     }
  12.  
  13.   Test.prototype.Add = function() {
  14.     this.counter += this.value;
  15.   };
  16.  
  17.   Test.prototype.Flip = function() {
  18.     this.value *= -1;
  19.   };
  20.  
  21.   Test.prototype.Go = function(scope) {
  22.     var body = document.getElementsByTagName("h1")[0];
  23.     body.innerHTML = scope.counter;
  24.     scope.Add();
  25.     if (scope.counter == 10)
  26.       scope.Flip();
  27.     else if (scope.counter==0)
  28.       scope.Flip();
  29.     setTimeout(scope.Go, 1000, scope);
  30.   };
  31.  
  32.   return Test;
  33. })();
  34.  
  35. </script>
  36. <style type="text/css">
  37. h1 { text-align: center; font-size: 72pt; }
  38. </style>
  39. </head>
  40. <body>
  41. <h1>hello. world!</h1>
  42. <script>
  43. var t = new Test();
  44. t.Go(t);
  45. </script>
  46. </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement