Counter script doesn't work..

Hey Guys!
I want to display 3 counters on my page, it should count from zero to something to show how many customers we have etc.
I copied this code from a forum discussion:

  1. let startNum = 6500;

  2. let endNum = 7000;

  3. const duration = 9; // 1000 milliseconds

  4. $w.onReady( function () {

  5. setInterval(()=> {

  6. countUp();

  7. }, duration);

  8. });

  9. function countUp(){

  10. if (startNum <= endNum ){

  11. $w(’ #text68 ').text = startNum.toString();

  12. startNum++;

  13. }

  14. }

  15. let startNum1 = 7999980000;

  16. let endNum1 = 8000000000;

  17. const duration1 = 1; // 1000 milliseconds

  18. $w.onReady( function () {

  19. setInterval(()=> {

  20. countUp();

  21. }, duration);

  22. });

  23. function countUp1(){

  24. if (startNum <= endNum ){

  25. $w(’ #text69 ').text = startNum.toString();

  26. startNum++;

  27. }

  28. }

The first counter works fine, but i’m struggling with the 2nd and the 3rd. Someone with more coding experience, please provide me a working code, so i just have to make the textboxes and modify the numbers.

Thank you in advance!

If you’re incrementing all your counters at the same rate, and the first function works, then just build the other 2 around that.

let startNum = 6500;
let endNum = 7000;
let startNum1 = 7999980000;
let endNum1 = 8000000000;
const duration =  9; // 1000 milliseconds
$w.onReady(function () {
  setInterval(()=> {
  countUp();
  }, duration);
});

function countUp(){
  if (startNum <= endNum ){
    $w('#text68').text = startNum.toString();
    startNum++;
  }
  if (startNum1 <= endNum1 ){
    $w('#text69').text = startNum1.toString();
    startNum1++;
  }
}

and if you’re wondering why the second one you posted doesn’t work, it is because you are not calling it anywhere that I can see

what if endNum is a number that is collected from a database?

i have just posted the solution for this. And the Corvid master helped fix it up. Link below to the thread

Dear Lala,

Thanks for your help.
What i have been trying to do, and has not worked so far is something like this:

import wixData from ‘wix-data’ ;
$w.onReady( function () {
wixData.query( “DADOS” ) // DADOS is my database
.eq( “teusmov” ) // teusmov is a column in my database with a number
.find()
.then((results)=> {
let item = results.items[ 0 ];
$w( " #text38 ").text = item.toString();
});
});

I am trying to get the number on “teusmov” column and display it on " #text38 ".
This is the challenge (for me, a total newbie to corvid/java).
Wish you well.

import wixData from ‘wix-data’ ;
$w.onReady( function () {
wixData.query( “DADOS” ) // DADOS is my database
// you need to remove this .eq(" teusmov") from here
.find() //this will return all records in the dataset
.then((results)=> {
let items = results.items; //this will store the rows in an items variable let item=items[ 0 ]; //this will store the first row in the item variable let teusmov = item. teusmov ; //this will store the teusmov value you want in the teusmov variable
$w( " #text38 " ).text = teusmov .toString(); //then use the teusmov variable
});
});

Hope this helps.

import wixData from ‘wix-data’ ;
$w.onReady( function () {
wixData.query( “DADOS” ) // DADOS is my database
// you need to remove this .eq(" teusmov") from here
.find() //this will return all records in the dataset
.then((results)=> {
let items = results.items; //this will store the rows in an items variable
let item=items[ 0 ]; //this will store the first row in an item variable
let teusmov = item. teusmov ; //this will store the teusmov value you want in a teusmov variable
$w( " #text38 " ).text = teusmov .toString(); //then use the teusmov variable to send to the textbox
});
});

Hope this helps.