Page 1 of 8

how to calculate label values in an array

Posted: Mon Nov 18, 2013 8:18 pm
by Michael4771079

Hi Katya,
I have 2 arrays load to a page, there are labels in the arrays that contain number values, the labels names are "Price" in "mainorderArray" and "extrasprice" in "livesundriesArray"

is I need to add the "price" and "extrasprice" values together, i.e 5.00, + 10.50, after service is called and as page loads, based on the price labels in the arrays,
( we have 2 arrays, so 2 labels have _idx)
I will need to store the value of the labels in local and set property after that.
I hope I have explained the problem, if not please ask.

thanks again.


how to calculate label values in an array

Posted: Mon Nov 18, 2013 9:18 pm
by Kateryna Grynko

Hi Michael,

'a' and 'b' are source arrays, 'c' is a result array:prevar c = [];
if (a.length===b.length){
for (i = 0; i < a&#46;lenght; i++){
c&#46;push(a+b)};
}
}/pre


how to calculate label values in an array

Posted: Mon Nov 18, 2013 9:37 pm
by Michael4771079

Katya, this will prob make you laugh,:)

is this what you mean?

var totalprice = [];
if (Price.length===extrasprice.length){
for (i = 0; i < Price.lenght; i++){
totalprice.push(Price+extrasprice)};
}
}


how to calculate label values in an array

Posted: Mon Nov 18, 2013 9:41 pm
by Kateryna Grynko

Michael,

Looks nice :) Try if this works for you.


how to calculate label values in an array

Posted: Tue Nov 19, 2013 11:50 am
by Michael4771079

Hi
I have tried to use the code above to calculate the values of the labels in 2 arrays.
I created a variable called totalprice and the code runs on success of service calling the arrays. STARUSERREAD

When I click the checkout button on vegetarian pizza page I am getting an error, the error doesnt show when I delete the code above.
Here is the error, is there a mistake in my code?

Image


how to calculate label values in an array

Posted: Tue Nov 19, 2013 12:40 pm
by Maryna Brodina

Hello! You have extra right bracket "}". Please delete it, for example the last one.


how to calculate label values in an array

Posted: Tue Nov 19, 2013 1:04 pm
by Michael4771079

Tried that Marina,
but I got this error "Price" is one of the labels name

Image


how to calculate label values in an array

Posted: Tue Nov 19, 2013 1:17 pm
by Maryna Brodina

Could you give us your publick link, clarify how to reproduce it and what do you want to have as result?


how to calculate label values in an array

Posted: Tue Nov 19, 2013 1:45 pm
by Michael4771079

Hi Marina,
here is the link
http://appery.io/app/mobile-frame?src...

to reproduce,
login, you can use "a" as login and pass,
click menu, click pizza, click vegetarian pizza, select pizza and click to order any pizza.
click checkout in the navbar
on load of this page "checkout" the service STARUSERREAD is called, on success of service the code is run

codevar totalprice = [];
if (Price&#46;length===extrasprice&#46;length){
for (i = 0; i < Price&#46;lenght; i++){
totalprice&#46;push(Price+extrasprice)};
} /code

this image shows an example of both arrays in localstorage, the prices are the labels I need to total up
so I was hoping to calculate all price labels on page load and store result in variable "totalprice"

Image

thanks


how to calculate label values in an array

Posted: Tue Nov 19, 2013 1:46 pm
by Michael4771079