Page 2 of 8

how to calculate label values in an array

Posted: Tue Nov 19, 2013 3:49 pm
by Kateryna Grynko

Hi Michael,

'Star Pizza' seems to be another application. Are you sure it's 'Star Pizza'? We do not see any service handlers on 'checkout' page.


how to calculate label values in an array

Posted: Tue Nov 19, 2013 4:02 pm
by Michael4771079

Hi Katya,
yes it star pizza, this is the data tab on checkout page

Image


how to calculate label values in an array

Posted: Tue Nov 19, 2013 5:07 pm
by Kateryna Grynko

Hi Michael,

[quote:]Price is not defined.[/quote]Where do you declare 'Price' variable? Please note 'price' and 'Price' are different names.


how to calculate label values in an array

Posted: Tue Nov 19, 2013 5:19 pm
by Michael4771079

Katya,
I have changed the code to price and the error has changed to this
I dont have price as a variable

Image

Image

Image


how to calculate label values in an array

Posted: Tue Nov 19, 2013 9:28 pm
by Kateryna Grynko

Michael,

This is because you don't have a variable named "price".
There is also a typo. Please replaceprea.lenght/prewithprea.length/pre


how to calculate label values in an array

Posted: Tue Nov 19, 2013 9:44 pm
by Michael4771079

Hi Katya,
I have corrected the typo and add "price" and "extrasprice" as localstorage variables, I still get this error, how do I define these variables

Image


how to calculate label values in an array

Posted: Tue Nov 19, 2013 10:33 pm
by Alena Prykhodko

When you add variables to localStorage, you should call them next:pre localStorage.getItem("name");/pre

where name - name of variable.

In your case better to add this lines before your code:
pre
var price = localStorage.getItem("price");
var extrasprice = localStorage.getItem("extrasprice ");/pre


how to calculate label values in an array

Posted: Tue Nov 19, 2013 10:48 pm
by Michael4771079

HI Alena,
I have added the code above, here is the new error "price is null"

Image

Image


how to calculate label values in an array

Posted: Wed Nov 20, 2013 10:19 am
by Maryna Brodina

Hello! As you need arrays, not strings replace prevar price = localStorage.getItem("price");
var extrasprice = localStorage.getItem("extrasprice ");/pre with prevar price;
try {
price = JSON.parse(localStorage.getItem("price"));
if ({}.toString.call(price) !== "[object Array]") {
price = [];
}
} catch ( e ) {
price = [];
}

var extrasprice;
try {
extrasprice = JSON.parse(localStorage.getItem("extrasprice"));
if ({}.toString.call(extrasprice) !== "[object Array]") {
extrasprice = [];
}
} catch ( e ) {
extrasprice = [];
}/preAs we can see from your last error screenshot you don't have price localStorage variable. Please check localStorage variable name (note it's case sensitive). Check if it's saved correctly.


how to calculate label values in an array

Posted: Wed Nov 20, 2013 12:37 pm
by Michael4771079

Hi Marina,
I have added the code, I run the app but the code has no effect, errors are gone but nothing shows in localstorage
here are s/s of the code, the localstorage variables and the result of localstorage in firebug

Image

Image

Image