Type Tutor : Game « Page Components « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Event
7. Event onMethod
8. Form Control
9. GUI Components
10. HTML
11. Javascript Collections
12. Javascript Objects
13. Language Basics
14. Node Operation
15. Object Oriented
16. Page Components
17. Security
18. Style Layout
19. Table
20. Utilities
21. Window Browser
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript DHTML » Page Components » Game 
Type Tutor

<html><head><title>jsTypingTutor</title>
<!-- jsTypingTutor_lib.js -->
<script language="JavaScript">
/*
#-----------------------------------------------------------------------------
# Name:        jsTypingTutor
# Purpose:     To help build typing speed in users
#              and in developers.
#
# Author:      Jason Don Stracner
#
# Created:     2001/10/06
# RCS-ID:      $Id: jsTypingTutor_lib.js $
# Copyright:   (c) Little Rock Technology Consulting
# Licence:     GPL
#-----------------------------------------------------------------------------

jsTypingTutor - Source Code Documentation

This file is the JavaScript code for jsTypingTutor.  This
project is intended to help users develop faster typing
by simply re-typing text.  The sample text files that are
included are mainly computer code.  Computer code is thought
to make fuller use of the keyboard.  It is a simple matter 
to add your own text to the HTML file and have any text
displayed.
*/

var objTimer=null;
var rStartTime=0;
var rSecondsPassed_=0;
var rPauseStart_=0;
var iStrLen_=0;
var sStatMsg="";

/**
  * Sets text in txtStats_ on the HTML page on a timed interval.
  *
  *
  **/
function timer() {
  var dtNow_ = new Date();

  rSecondsPassed_ = dtNow_.getTime();
  rSecondsPassed_ = rSecondsPassed_ / 1000;
  rSecondsPassed_ = Math.round(rSecondsPassed_ - rStartTime);
  iStrLen_ = document.frmTyping_.txtTop_.value.length;
  iStrLen_ = iStrLen_ + document.frmTyping_.txtTypeHere_.value.length;
  sStatMsg="Characters: " + iStrLen_;
  sStatMsg += "  Seconds Passed:" + rSecondsPassed_;
  sStatMsg += "  Word per minute:" + Math.round((iStrLen_ / rSecondsPassed_)(60));
  document.frmTyping_.txtStats_.value=sStatMsg;
}

/**
  * Called by button in HTML to start running the
  * 'timer' function on a timed interval.
  *
  **/
function startTimer() {
  rStartTime = parseInt((new Date).getTime()/1000);
  rSecondsPassed_=0;
  endTimer();
  objTimer = setInterval("timer();",1000);
}

/**
  * Called by button in HTML to pause the running 
  * of the 'timer' function on a timed interval.
  *
  **/
function pauseTimer() {
  rPauseStart_ = parseInt((new Date).getTime()/1000);
  if (objTimer != null) {
    clearInterval(objTimer);
    objTimer = null;
  }
}

/**
  * Called by button in HTML to resume the running 
  * of the 'timer' function on a timed interval.
  *
  **/
function resumeTimer() {
  rStartTime=rStartTime+(parseInt((new Date).getTime()/1000)-rPauseStart_);
  if (objTimer != null) {
    clearInterval(objTimer);
    objTimer = null;
  }
  objTimer = setInterval("timer();",1000);
}

/**
  * Called by button in HTML to stop running the
  * 'timer' function on a timed interval.
  *
  **/
function endTimer() {
  rSecondsPassed_ = 0;
  if (objTimer != null) {
    clearInterval(objTimer);
    objTimer = null;
  }
}

/**
  * Checks the content of the textbox 'txtTypeHere_'
  * and eleminates any incorrect characters.
  *
  **/
function validateTyping(e) {

  var isNN = (navigator.appName.indexOf("Netscape")!=-1);

  if (isNN) {
    sChar = String.fromCharCode(e.which);
  else {
    sChar = String.fromCharCode(event.keyCode);
  }

  var iTypedLength =  document.frmTyping_.txtTypeHere_.value.length;
  var sInitialValue = document.frmTyping_.txtBottom_.value.substring(0,iTypedLength);
  var sTestChunk =    document.frmTyping_.txtTypeHere_.value.substring(0,iTypedLength+ sChar;
  var sCorrectChunk = document.frmTyping_.txtBottom_.value.substring(0,iTypedLength+1);

  
  if (sTestChunk != sCorrectChunk) {
    document.frmTyping_.txtTypeHere_.value=sInitialValue;
  else {
    document.frmTyping_.txtTypeHere_.value=sCorrectChunk;
  }

  if (escape(document.frmTyping_.txtBottom_.value.charAt(iTypedLength))=="%0D") {
    document.frmTyping_.txtTop_.value+= "\n" +
    document.frmTyping_.txtBottom_.value.substring(0,iTypedLength);
    document.frmTyping_.txtBottom_.value=
    document.frmTyping_.txtBottom_.value.substring(iTypedLength+2,document.frmTyping_.txtBottom_.value.length);
    document.frmTyping_.txtTypeHere_.value="";
  }
  
  //There should never be a return character at the end.
  if (escape(document.frmTyping_.txtTypeHere_.value.charAt(iTypedLength-1))=="%0A") {
    // Remove return character.
    document.frmTyping_.txtTypeHere_.value=
       document.frmTyping_.txtTypeHere_.value.substring(0,iTypedLength-2);
  }
}

</script>

</head>
<body text="#0000ff">
<strong><center><font size="+2">jsTypingTutor</font></center></strong>
<hr align="center" size="2" width="25%">
<br>
<br>
<center>
<form name="frmTyping_"><b>T</b>yping statistics:<br>
<textarea name="txtStats_" rows="1" cols="80"></textarea><br>
<input onclick="startTimer()" value="Start" name="cmdStartTimer_" type="button"
<input onclick="pauseTimer()" value="Pause" name="cmdPauseTimer_" type="button"
<input onclick="resumeTimer()" value="Resume" name="cmdResumeTimer_" type="button"
<input onclick="endTimer()" value="Stop" name="cmdEndTimer_" type="button"><br>
<textarea name="txtTop_" rows="8" cols="80"></textarea><br>
<small><b>T</b>ype text into this area:</small><br>
<textarea name="txtTypeHere_" rows="1" cols="80" onkeypress="validateTyping(event);return false;"></textarea>
<textarea name="txtBottom_" rows="8" cols="80">Instructions:
Paste some text into this area then press the 'Start button'.
</textarea><br>
</form>
</center>
</body></html

           
       
Related examples in the same category
1. Chess: Draughts
2. Mine game
3. Word search game
4. Ranisima english
5. Yasminuroban (by Joan Alba Maldonado)
6. Level editor for Yasminuroban by Joan Alba Maldonado
7. js mine sweeper
8. Another tictactoe
9. Marbles
10. Jigsaw
11. Game sudoku
12. Game PunkPong
13. Tetris in Javascript
14. Arrange Game
15. Guess Number
16. Tic tac toe
17. Count Game
18.  A JavaScript Hangman Game
19. Game library
20. Game: Place It (IE only)
21. HylZee
ww___w_.__j_a___v___a_2___s__.com_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.