PDA

View Full Version : Problem with 00 in array

noface0711
04-15-2016, 04:20 AM
Hi guys,
I had a programmer working on a custom garden builder but ran into personal issues just at the end of completing the job so I am now trying to do this myself. Unfortunately I am no expert programmer when it comes to javascript so looking for help with this one. Right now we have prices for sheds depending on the size (width and length)... so a 1.5m x 1.8m shed is a price, 2.1m x 3.6m is a price and so on. The programmer has used arrays to work out the pricing so for example 1.5m equals 1 and 3m equals 8... the price is hen worked out by matching the array values so the example I gave would use 1 and 8 as 18 to work out the price. I have posted a snippet of the code below to show how this works:

priceArray[99] = 1690;
priceArray[90] = 1845;
priceArray[01] = 540;
priceArray[02] = 720;
priceArray[03] = 840;
priceArray[04] = 970;
priceArray[05] = 1130;
priceArray[06] = 1300;
priceArray[07] = 1480;
priceArray[08] = 1680;
priceArray[09] = 1845;
priceArray[00] = 2100;
there are many variations but this is just a sample of some. All the prices are working out fine apart from the very last one. The 0 equals 3.8m so a 3.8m x 3.8m shed would be 00. Unfortunately this is the only price in the code that isn't working. Again I am no programmer but all the other prices work fine so I can only assume that the priceArray[00] isn't working because of the 00 value probably being converted as 0.

I would change the 0 to something else to represent 3.8m but the values 1-9 have all been used so I am left with 0 as the only single number left. I have thought about trying 10 as a value instead so a 3.8m x 3.8m shed would be priceArray[1010] = 2100 but then this means changing the other numbers too and I know this is just going to mess things up.

My question is basically how can I have priceArray[00] to show £2100? any ideas?

Any help would be much appreciated.

Kind regards,

jscheuer1
04-15-2016, 05:18 AM
I don't know what the problem is. I don't see enough code to say for sure. I do see enough code to know that what you have there isn't a traditional javascript array. It has gaps and inconsistencies. Numbers are numbers and in a javascript array are indexes. Generally you go from [0] to [1] to [2] and so on. You obviously do not seem to be doing that. 00 is no different than 0. 01 is no different than 1. This might be part of what is happening. If you need to use the current convention you have (two numbers for each index, many of them out of sequence), I would be tempted to quote everything and hope for the best (this would essentially turn the array into an object, as long as you were consistent in the rest of your code, that could work):

priceArray["99"] = 1690;
priceArray["90"] = 1845;
priceArray["01"] = 540;
priceArray["02"] = 720;
priceArray["03"] = 840;
priceArray["04"] = 970;
priceArray["05"] = 1130;
priceArray["06"] = 1300;
priceArray["07"] = 1480;
priceArray["08"] = 1680;
priceArray["09"] = 1845;
priceArray["00"] = 2100;

Also I'm not convinced this is javascript. It could be, but I'm thinking it might be straight Java (a server side language). But, even if so, my advice MIGHT still work. Either way (javascript or Java), much depends upon the rest of the code - the parts that you have not posted.

You MIGHT also have luck with:

priceArray[99] = 1690;
priceArray[90] = 1845;
priceArray[01] = 540;
priceArray[02] = 720;
priceArray[03] = 840;
priceArray[04] = 970;
priceArray[05] = 1130;
priceArray[06] = 1300;
priceArray[07] = 1480;
priceArray[08] = 1680;
priceArray[09] = 1845;
priceArray["00"] = 2100;

Or not.

If you want more help, please provide a link to the page on your site that contains the problematic code.

Also - if you know, is this Java or javascript?