Coding on Editor X – HELP

Hi,

I need to code a number count for the number below.
What’s not working:

  1. Doesn’t display as the exact number. Only as 53 000 000
  2. How can I end the number with a “+” sign?
  3. When website is published, the coding doesn’t display.

Here’s my code below:

let startNum1 = 1000000 ;
let endNum1 = 53000000 ; note: (ideally I want it to end as 53231661)
const duration1 = 10 ; // 1000 milliseconds

$w . onReady ( function () {
setInterval (()=> {
countUp1 ();
}, duration1 );
});

function countUp1 ( ){
if ( startNum1 <= endNum1 ){
$w ( ‘#text10’ ). text = startNum1 . toLocaleString (). toString ();
startNum1 += 500000 ;
}
}
–––––––––––––
Can anyone help?

@vivancompaulo I’d suggest posting this question on the Velo forum. That’s where the coding experts hang out: https://www.wix.com/velo/forum/coding-with-velo

@jim75924 Thank you, will do!

Something like this: https://chief-developer.editorx.io/countup

If yes, I will send you the sample website so that you can take the code and use it to suit your need.

@getintouchishaq Yes, please! Also, would you happen to know how to trigger the animation to start when the page is scrolled to? It seems to start as soon as the website loads. Thanks!

@vivancompaulo You mean the counting should start once a user scrolls up?

I have adjusted the code, check see if it that’s what you mean

@getintouchishaq Looks great! the only difference that I see is that my number is on section 3 only, it doesn’t show throughout the website As you scroll. Do you think that would make a difference?


@Paulo You can adjust the code to fit your need. If you want contineous counting or you want to cut the counting short at a certain point. I update the code again to cut the counting short. You can adjust it however you'd like.

Here is my code:

var startingNumber;
var endingNumber;
var currentNumber;
var taskValue;
var taskDuration;

$w.onReady(() => {

    startingNumber = String(Number(1000));
    endingNumber = String(Number(125175));
    currentNumber = startingNumber;
    taskDuration = 10;

    $w("#trigger").onViewportEnter(() => {
        stepOne();
    })

})

function stepOne() {

    $w("#textOne").text = currentNumber;

    if (taskDuration <= 1000) {
        if (currentNumber !== endingNumber) {

            taskValue = currentNumber;
            stepTwo();

        } else {
            $w("#textOne").text = currentNumber + "+";
        }
    } else {
        $w("#textOne").text = endingNumber;
    }

}

function stepTwo() {
    setTimeout(() => {
        taskDuration = String(Number(taskDuration) + 10);
        currentNumber = String(Number(taskValue) + 25)
        stepOne()
    }, 10)

}

$w.onReady(() => {
    $w("#section5").onViewportEnter(() => {
        $w("#textOne").text = endingNumber;
    })
})

I hope this helps you accomplish your need. Cheers

Hello Paulo. I also often have problems with the code. After all, I’m in the process of learning Java and much is still not clear. I try to read as much quality material as possible on web development and programming. And perhaps this article https://www.programmingassignment.net/blog/best-tips-for-junior-developers/ will help you deal with the problem. I read it recently and learned a lot of new and useful things for myself. And if this does not help, then it is better to turn to experienced professionals for help.