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 8564907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:18:08+00:00 2026-06-11T17:18:08+00:00

I have found a nice jquery increment script. The increment portion can accept a

  • 0

I have found a nice jquery increment script. The increment portion can accept a function or just a regular number. I am looking to increase at a random number between 1 and 100. How would I write the function for this?

$( document ).ready( function()
{
  $( '.tick' ).ticker(
  {
    incremental : 1,
    delay       : 1500,
    separators  : true
  });
   $(".comma-change").html(".");  
});

<span class="tick">2,354,456</span>

So rather than increase by 1 in the incremental field, I would like to write a function that updates with a random number. With the help of other posts I can write the function that creates a random number no problem:

function random_generator (min, max) {
    return Math.random() * (max - min) + min;
}

but I am having trouble working it into this directly.

Here is the increment portion of the plugin:

  Tick = (function() {

    function Tick(element, options) {
      this.element = element;
      if (options == null) options = {};
      this.running = false;
      this.options = {
        delay: options.delay || 1000,
        separators: options.separators != null ? options.separators : false,
        autostart: options.autostart != null ? options.autostart : true
      };
      this.increment = this.build_increment_callback(options.incremental);
      this.value = Number(this.element.html().replace(/[^\d.]/g, ''));
      this.separators = this.element.html().trim().split(/[\d]/i);
      this.element.addClass('tick-active');
      if (this.options.autostart) this.start();
    }

    Tick.prototype.build_increment_callback = function(option) {
      if ((option != null) && {}.toString.call(option) === '[object Function]') {
        return option;
      } else if (typeof option === 'number') {
        return function(val) {
          return val + option;
        };
      } else {
        return function(val) {
          return val + 1;
        };
      }
    };

and then this bit:

Tick.prototype.tick = function() {
  this.value = this.increment(this.value);
  this.render();
  return this.set_timer();
};
  • 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-06-11T17:18:09+00:00Added an answer on June 11, 2026 at 5:18 pm

    All you need to do is translate your function statement into a function expression. A function statement defines a name and assigns it a function whereas a function expression is the function itself (an anonymous function).

    You can set the value of a variable to a function like this

    var random_generator = function(min, max) {
        return Math.random() * (max - min) + min;
    };
    

    and then pass the reference to this function (the variable random_generator) as the incremental to your plugin. Or you could inline the function definition like this:

    $( '.tick' ).ticker({
        incremental : function(currentValue) {
                         // currentValue really is the current value of the ticker
                         // this is because the code inside the ticker plugin, that triggers
                         // your function, will take care of passing it as a parameter in
                         return +currentValue + random_generator(1, 100);
                      },
        delay       : 1500,
        separators  : true
    });
    

    edit: I didn’t realize, that your function has two parameters… that makes the whole thing a little bit more sophisticated. You could either hardcode min and max into your function (because the function gets invoked by code from the plugin and you will most definitely not get any arguments), or wrap another anonymous function around it, that provides the two parameters for us.

    Final edit: I guess you are using this plugin https://github.com/harvesthq/tick ? This plugin can accept a function that will be called every tick and gets passed in the current value of the ticker. You have to provide the new value. I updated the code snippet accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found and customized this JQuery script, which displays different content when different
I have just found a nice look that I would like to use for
I found a nice script for dropdowns. The thing is, I'm trying to have
I have found Okapi Similarity measure can be used to calculated document similarity from
I have found that call stack helps in finding the line number of a
I have found some jQuery codes for show content with slide effect, but none
I'm in search for a jQuery-based Date/Time Selector. I have found a few that
I recently used a nice little jquery script that loads images with a given
By using Google I have found some nice snippets of example code for using
I have found nice code, that stylize checkboxes. HTML: <input id=checkbox type=checkbox class=checkbox />

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.