Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6727259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:01:44+00:00 2026-05-26T10:01:44+00:00

I have a function that displays words at various speeds. The function starts OK,

  • 0

I have a function that displays words at various speeds. The function starts OK, but I can’t seem to get the code right to stop it again.
I know I have to use clearInterval and I assume that this is to clear the var myTimer – but I can’t get this to work.

Any help would be appreciated

HTML

<input type="button" value="Start" onclick="wpm($numberWords,$speed)" />
<input type="button" value="Stop" onclick="stopWpm()" />

JS

var myTimer;

function wpm(numberWords,speed) {

    var input = new Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s");

    var output = new Array();
    for (var i = 0; i < input.length; i += numberWords) {
        output.push(input.slice(i, i + numberWords).join(" "));
    }

    var i=0;
    var myTimer =setInterval(timer,speed); //1000 will run it every 1 second
    function timer() {
        document.getElementById("timer").innerHTML = output[i];
        i++;
        if (i == output.length){
            clearInterval(myTimer);
        }
    }
}   

function stopWpm() {
    clearInterval(myTimer);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:01:45+00:00Added an answer on May 26, 2026 at 10:01 am

    you have myTimer; as a global var and within wpm() you have redeclared it try removing the var from myTimer within wpm() function

    // ...
    var i=0;
    myTimer = setInterval(timer,speed); //1000 will run it every 1 second
    function timer() {
    // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a JS function that displays a widget at the bottom of
In my Java code I have function that gets file from the client in
I have a site that displays items, 12 items per page and I can
I have a function that gets the contents of a table row and displays
A simple problem that I just can't find the 'right' answer too. I have
I have a javascript function that toggles the display for rows in a table.
So I have function that formats a date to coerce to given enum DateType{CURRENT,
I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035
I have a function that gets x(a value) and xs(a list) and removes all
I have a function that takes, amongst others, a parameter declared as int privateCount

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.