Streaming live at 10am (PST)

Math using CMS fields

side question: Can you also put the sum with punctuation? so 1000 » 1.000 and 1000000 » 1.000.000 ?

You need to replace the cars = [] of your old code snipet by the new one, there shouldn’t be two times cars = [] in your code. As for the <p>total: <span id="target"></span></p> you can simly inject it into a webflow custom code embed component within your layout. The '...' or quotes wrapping your numbers in your javascript have no effect because in the script I wrote, I wrapped the a and b values within the Number() method which coherce strings into numbers. If the quotes would have been an issue, you’d see a NaN (Not a Number) value into your target span. As for your formating question, sure it’s possible to format the numbers with punctuation, that is one or two javascript lines.

1 Like

If i replace the cars = [] the script doesn’t run and the google map doesn’t get populated.

then ‘cars’ is not defined devtools reports:

i removed cars = [], from your snippet and kept the original! Now it’s seems to WORK!!!



Super awesome!!!
Now i only need to get the punctuation?
Do you perhaps have any example(s) to do this?

Cool, I’m happy it worked :wink:

1 Like

yes, I did a similar codepen a few month ago.

wow that’s a bit more than two lines.
I’ve googled a bit and found this:

function numberWithCommas(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

could it work with this as well?

you can try :slight_smile:

I’ve gotten it to work with:

Last question - how can i ‘count’ the total length (amount of items) of the array(s) and inject them to some span as well?

You can use the .length method to return the amount of items in an array.

1 Like