Easy one, your help needed. Divide words to minutes

Discussion in 'JavaScript' started by cabdirazzaq, Jan 29, 2007.

  1. #1
    I have this script that calculates how fast one reads. The things is, it gives you the result in this format. How can I change this so the script divides the number of words with the time, ie. words per minute (wpm)?

    Thank you in advance
     
    cabdirazzaq, Jan 29, 2007 IP
  2. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Consider this

    2 Words = 0.164 minutes
    X Words = 1 Minute

    to get your answer, cross multiply (that is 2x1 = 0.164X) th then divide by 0.164 which will give you 12.2

    Basically what you are asking is 2 words equals 0.164 minutes. How many words equals 1 minute? That's how you get the answer

    HTH
     
    datropics, Jan 29, 2007 IP
    cabdirazzaq likes this.
  3. cabdirazzaq

    cabdirazzaq Banned

    Messages:
    150
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for your quick answer (added some rep).
    Not really. The two words thing is just a sample. The script counts the number of words and then tells you how many minutes have passed since you pressed the start button.

    Instead of (for example): "You read 100 words in 0.5 minutes" I want it to be "You read 200 wpm" i.e > 100/0.5

    Im sorry if my title was some what deluding
     
    cabdirazzaq, Jan 30, 2007 IP
  4. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #4
    same rule applies. Find out the number of words. Then find out the number of minutes passed then do the cross multiplication then division again to find out the wpm

    Headed to work now - will check your reply when I get in the office

    HTH
     
    datropics, Jan 30, 2007 IP
  5. cabdirazzaq

    cabdirazzaq Banned

    Messages:
    150
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yea I know, but how do I do this in java script? I'm a serious newbie here ^^
     
    cabdirazzaq, Jan 30, 2007 IP
  6. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Hi no problem - I made a few changes to your script - this is what I came up with:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Antigua Classifieds | Free Ads Online in Antigua | Classifed Ads Antigua</title>
    <SCRIPT type=text/javascript>
    var StartTime;
    var EndTime;
    var TimeInMinutes;
    var DateObject;
    var txtArray;
    var numWords;
    var WPM;
    var HowManyWordsInHowManyMinutes = 1;
    function CountWords(Text)
    {
    return Text.replace(/\b.+\b/g, '').length + 1;
    }

    function StartTimer()
    {
    //A simple function to count the words in the DIV
    txtArray = document.getElementById("ReadingMaterial").innerText.split(" ");
    numWords = txtArray.length - 1;
    DateObject = new Date;
    StartTime = DateObject.getTime();
    document.getElementById("StartButton").disabled = true;
    document.getElementById("StopButton").disabled = false;
    }

    function StopTimer()
    {
    DateObject = new Date;
    EndTime = DateObject.getTime();
    window.status = EndTime + " " + StartTime;
    //var Result = "You read "+CountWords(document.getElementById("ReadingMaterial").innerHTML)+" words in "+((DateObject.getTime() - StartTime)/6000)+" minutes.";
    //Amount of time took to read the text;
    //Round to 2 decimal places
    TimeInMinutes = Math.round((EndTime - StartTime) / 60000 * 100) / 100;
    //Now I cross multiply
    /*
    numWords = TimeInMinutes
    X Words = 1 Minute

    which is numWords / TimeInMinutes * 1 (1 minute) so...
    */
    //I multiply by one because I want to find out how many words in 1 minute.
    //If it was 5 minutes then I'd multiply by 5
    WPM = Math.round(numWords / TimeInMinutes * HowManyWordsInHowManyMinutes);
    var Result = "Your read " + numWords + " words in " + TimeInMinutes + " minutes. Your reading speed is " + WPM + " words per minute!";
    document.getElementById("Result").innerHTML = Result;
    StartTime = '';
    document.getElementById("StartButton").disabled = false;
    document.getElementById("StopButton").disabled = true;
    }
    </SCRIPT>

    </head>

    <body>
    <INPUT id=StartButton onclick=StartTimer() type=button value="Click me to start timer">
    <DIV id=ReadingMaterial>
    <p>Whenever single-loop learning strategies go wrong, whether the organization's
    core competences are fully in line, given market realities highly motivated
    participants contributing to a valued-added outcome. The balanced scorecard,
    like the executive dashboard, is an essential tool building a dynamic
    relationship between the main players. Maximization of shareholder wealth
    through separation of ownership from management exploiting the productive
    lifecycle big is no longer impregnable. Working through a top-down, bottom-up
    approach, to focus on improvement, not cost, highly motivated participants
    contributing to a valued-added outcome. Taking full cognizance of organizational
    learning parameters and principles, from binary cause and effect to complex
    patterns, in a collaborative, forward-thinking venture brought together
    through the merging of like minds.</p>
    <p>Through the adoption of a proactive stance, the astute manager can adopt
    a position at the vanguard. Building a dynamic relationship between the
    main players. Organizations capable of double-loop learning, highly motivated
    participants contributing to a valued-added outcome. Taking full cognizance
    of organizational learning parameters and principles, that will indubitably
    lay the firm foundations for any leading company the strategic vision
    - if indeed there be one - is required to identify. Exploitation of core
    competencies as an essential enabler, the components and priorities for
    the change program empowerment of all personnel, not just key operatives.</p>
    <p>Presentation of the process flow should culminate in idea generation,
    maximization of shareholder wealth through separation of ownership from
    management in order to build a shared view of what can be improved. An
    important ingredient of business process reengineering big is no longer
    impregnable exploiting the productive lifecycle. To focus on improvement,
    not cost, highly motivated participants contributing to a valued-added
    outcome. The balanced scorecard, like the executive dashboard, is an
    essential tool while those at the coal face don't have sufficient view
    of the overall goals.</p>
    </DIV>
    <INPUT id=StopButton disabled onclick=StopTimer() type=button value="Click me to stop timer">
    <DIV id=Result></DIV>
    </body>
    </html>
     
    datropics, Jan 30, 2007 IP
  7. cabdirazzaq

    cabdirazzaq Banned

    Messages:
    150
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Wow, nice of you to do that. But for some reason I can't press the stop button???
     
    cabdirazzaq, Jan 30, 2007 IP
  8. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #8
    My apologies:

    Replace
    txtArray = document.getElementById("ReadingMaterial").innerText.split(" ");

    With:
    if(document.all)
    {
    txtArray = document.getElementById("ReadingMaterial").innerText.split(" ");
    } else
    {
    txtArray = document.getElementById("ReadingMaterial").textContent.split(" ");
    }
     
    datropics, Jan 30, 2007 IP
  9. cabdirazzaq

    cabdirazzaq Banned

    Messages:
    150
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thank you very much, really nice of you!
     
    cabdirazzaq, Jan 30, 2007 IP
  10. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #10
    that's what the forums are for - now you go and do the same...
     
    datropics, Jan 30, 2007 IP