Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

how to calculate label values in an array

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.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

how to calculate label values in an array

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

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

how to calculate label values in an array

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)};
}
}

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

how to calculate label values in an array

Michael,

Looks nice :) Try if this works for you.

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

how to calculate label values in an array

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

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

how to calculate label values in an array

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

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

how to calculate label values in an array

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

Image

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

how to calculate label values in an array

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

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

how to calculate label values in an array

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

Return to “Issues”