Arithmetic Using Code

I’m wondering if its possible to do basic arithmetic using Wix Code. For instance, when a user fills out a form where dimensions are required (W x H x L), I want the site to collect the input and generate an output in Volume.

Of course. WixCode understands all of Javascript, except for anything that accesses the DOM (This keeps the user from inadvertently “breaking” something). So you can do calculations as complex as you want, and then display the results in a text field.

Thanks Yisrael. Would I be able to display the result in real-time (without page refresh). Trying to simulate something like this

where when the dimensions are entered, the volume is automatically generated and displayed.

Yes - calculate, set the display field to the result, and it appears.

i would suggest starting to play around. For instant gratification, visit the Examples page and play around with the different example apps. Then dig into the Wix Code docs and learn about all the wonderful thikngs you can do with Wix Code.

Have fun,

Yisrael

Alright thanks, I shall dive right in!

So I have written the following code to extract data from fields called var1 and var2 and add them together. I am stuck however on how to push the result out to the field called ‘result’ in the same dataset. I am very new to JavaScript.

import wixData from ‘wix-data’;

export function test()
{
//Totali in lista
const firstPromise = wixData.query(“TestData”).count()
.eq(“var2”, true )
.count();
//Totali iscritti
const secondPromise = wixData.query(“TestData”)
.eq(“var1”, true )
.count();

Promise.all([firstPromise, secondPromise]) 
    .then((a, b) => { 
        console.log(a+b); 
    }); 

}

I got this part of the code on another forum.