Top Banner

of 21

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

Introduction This is a somewhat advanced JavaScript Typing Test system that will allow you to place a table and a few blocks of code on your website (perhaps on a job application system as we did) and get a detailed statistical information on your user's typing ability, including: Words Per Minute (WPM) Accuracy Percentage Rating Total Words Typed Good Words / Bad Words Typed (Errors) Time Taken to Complete More as needed To see the system in use, visit http://www.itsllc.us/TypingTest_1.asp; you may also download a lower quality version above, or follow along with the code below. Background There isn't much of a background to this code except for the fact that it uses JavaScript as a base to execute -- and yes, this is completely client side scripted. You could do the same thing in a server side scripting language or environment such as ASP; however, it would more than likely be less effective. Using the code To implement the code below, simply write (or copy and paste -which is quicker, yeah) the code below into the section of your document -- or anywhere else as you wish, if you are using an include. Shown below is the JavaScript code required to make the system work. It's fairly straightforward, and very high on the "commented" side -- so you shouldn't have any issues understanding; but if you do, don't hesitate to leave a comment or contact me. Collapse | Copy Code //Holds whether or not we have already started the first typing test or now

// True = The test has already started // False = The test hasn't started yet var hasStarted = false; //strToTest is an array object that holds various strings to be used as the base typing test // - If you update the array, be sure to update the intToTestCnt // with the number of ACTIVE testing strings var intToTestCnt = 4; var strToTest = new Array("Innovative Technical Solutions, LLC (ITS) is a Native" + " American owned business that was established in Paducah, " + "Kentucky in April 2000. ITS is a certified and Small Disadvantaged " + "Business by the U.S. Small Business Administration. Our headquarters " + "are in Paducah, Kentucky and we have" + " satellite offices located in Tennessee, " + "Ohio, and Illinois. ITS is a leading" + " edge Information Technology firm that " + "is comprised of professionals with a broad" + " range of experience in software " + "development, high-speed imaging/scanning (TIFF, PDF, Text, " + "and OCR capabilities), document management, records management," + " relevance management, information security, environmental " + "management, fire services management, fire protection "+ "engineering, and protective force expertise.", "The ITS Information Technology (IT) Team are experts "+

"in the identification, capture, indexing, microfilming, imaging, " + "disposition, turnover, storage, and retrieval of records, " + "and in the administration of records management databases. " + "The types of records we have extensive experience in managing " + "include waste management, hazardous waste, waste shipment, " + "environmental compliance, environmental" + " monitoring, feasibility studies, " + "environmental work plans, cleanup actions, cemetery records, and " + "various Federal laws such as CERCLA, Paper Reduction, " + "Pollution Prevention, and Clean Water and Air.", "Collectively, the professional background of key ITS personnel " + "demonstrates Fortune 100 Company experience that includes, " + "but is not limited to, DOE, the Department of Defense, EPA, the " + "Tennessee Valley Authority (TVA), Lockheed Martin Utility Services, " + "Lockheed Martin Energy Systems, British Nuclear Fuels Limited, various " + "state and local agencies, and USEC." + " We consider the depth and magnitude " + "of this experience as a proposition value " + "to both our current and future customers.", "With our years of experience, we completely understand document " + "management and technology. We know the importance of deadlines and " +

"we know the importance of production without error. We refuse to " + "over-commit to deadlines that can not be met. Dedication to excellence " + "in providing quality products and services through innovative ideas and " + "processes. Steadfast resolve to a positive working environment that " + "allows for the personal and professional development of all employees, " + "while sustaining project service, and customer satisfaction. " + "Commitment to the highest ethical management practices that " + "recognize client satisfaction as a top priority.") var strToTestType = ""; var checkStatusInt; //General functions to allow for left and right trimming / selection of a string function Left(str, n){ if (n String(str).length) return str; else return String(str).substring(0,n); } function Right(str, n){ if (n String(str).length) return str; else {

var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } } //beginTest Function/Sub initializes the test and starts //the timers to determine the WPM and Accuracy function beginTest() { //We're starting the test, so set the variable to true hasStarted = true; //Generate a date value for the current time as a baseline day = new Date(); //Count the number of valid words in the testing baseline string cnt = strToTestType.split(" ").length; //Set the total word count to the number of valid words that need to be typed word = cnt; //Set the exact time of day that the testing has started startType = day.getTime(); //Disable the printing button (if used, in this download it's not included) document.getElementById("printB").disabled = true; calcStat(); //Initialize the testing objects by setting the values //of the buttons, what to type, and what is typed document.JobOp.start.value = "-- Typing Test Started --"; document.JobOp.start.disabled = true;

document.JobOp.given.value = strToTestType; document.JobOp.typed.value = ""; //Apply focus to the text box the user will type the test into document.JobOp.typed.focus(); document.JobOp.typed.select(); } //User to deter from Copy and Paste, also acting as a testing protection system // Is fired when the user attempts to click or apply focus // to the text box containing what needs to be typed function deterCPProtect() { document.JobOp.typed.focus(); } //The final call to end the test -- used when the //user has completed their assignment // This function/sub is responsible for calculating // the accuracy, and setting post-test variables function endTest() { //Clear the timer that tracks the progress of the test, since it's complete clearTimeout(checkStatusInt); //Initialize an object with the current date/time //so we can calculate the difference eDay = new Date(); endType = eDay.getTime(); totalTime = ((endType - startType) / 1000) //Calculate the typing speed by taking the number of valid words

//typed by the total time taken and multiplying it by one minute in seconds (60) //***** 1A ***************************************************** ***** 1A ***** //We also want to disregard if they used a double-space after //a period, if we didn't then it would throw everything after the space off //Since we are using the space as the seperator for words; it's the //difference between "Hey. This is me. //" versus "Hey. This is me." and //Having the last three words reporting as wrong/errors due //to the double space after the first period, see? //**************************************************** ************************ wpmType = Math.round(((document.JobOp.typed.value.replace(/ /g, " ").split(" ").length)/totalTime) * 60) //Set the start test button label and enabled state document.JobOp.start.value = ">> Re-Start Typing Test