JavaScriptで、フラッシュ暗算?みたいなやつ。しかも無料

いつものように、OKWaveの質問に答えてみた。というか、回答は無視して自分なりのやり方で。そしたら、けっこうハマってしまった。俺、実力なら珠算一級、現実は珠算三級なんだけど、これがもう頭が回らん!どうしたものか?
今夜から特訓することにする。
http://okwave.jp/qa5520119.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<title>TEST</title>
<style type="text/css">
#no {
  color:#f00;
  font-size:300px;
  padding: 0;
  margin: 0;
  width: 800px;
  height: 350px;
  text-align:center;
  border: 2px #00f solid;
}

</style>

<body>
<div id="no">
?
</div>
<p>
  <input type="button" value="Start" onClick="Start()">
  <input type="text" value="" id="kotae">
  <input type="button" value="Check" onClick="Check()">
</p>

<script type="text/javascript">

var intRandom = function ( min, max, len ) {
  var a = new Array( len );
  var r = [ ];
  var s = max - min + 1;
  
  while( len-- ) r.push( Math.floor(Math.random() * s + min ) );
  return r;
}


var Flash = function ( ) {
  this.init.apply( this, arguments );
};


Flash.prototype.init = (function ( ) {
  return function ( id, vtime, htime, ary ) {
    this.target = document.getElementById( id );
    this.vtime = 'number' == typeof vtime ? vtime: 700;
    this.htime = 'number' == typeof htime ? htime: 100;
    return this.ary = ary;
  };
})();


Flash.prototype.stop = function ( ) {
  clearTimeout( this.tmid );
  return this.setString( 'Stop!!' );
};


Flash.prototype.start = (function ( ) {
  return function ( ) {
    this.setString( 'Start!!' );
    this.max = this.ary.length;
    this.mode = false;
    this.tmid = null;
    this.cnt = 0;
    setTimeout( (function(that){ return function(){ that.loop() }})(this), 500);
  };
})();


Flash.prototype.setString = (function ( ) {
  return function ( str ) {
    return this.target.firstChild.nodeValue = 'undefined' == typeof str ? '': str + '';
  };
})();


Flash.prototype.loop = (function ( ) {
  return function ( ) {
    var t = '?';

    if( this.max >= this.cnt ) {
      t = ( this.mode = ! this.mode ) ? '': this.ary[ this.cnt++ ];

      this.tmid = setTimeout( (function(that){ return function(){ that.loop() }})(this),
        this.mode ? this.htime: this.vtime );
    }
    this.setString( t );
  };
})();


Flash.prototype.getTotal = (function ( ) {
  return function ( ) {
    var t = 0, c = this.max, n;
    while( c ) t += this.ary[ --c ];
    return t;
  };
})();


Flash.prototype.setData = (function ( ) {
  return function ( ary ) {
    return this.ary = ary;
  };
})();


Flash.prototype.check = (function ( ) {
  return function ( total ) {
    return total == this.getTotal();
  };
})();

var mondai = new Flash( 'no', 400, 150);// id 表示ミリ秒、未表示ミリ秒

function Start( ) {
  document.getElementById( 'kotae' ).value = '';
  mondai.setData( intRandom( -10, 10, 5) );//表示される最小値、最大値、問題数
  mondai.start( );
}

function Check( ) {
  var t = document.getElementById( 'kotae' );
  t.value = mondai.check( t.value ) ? "正解": mondai.getTotal();
}


</script>