Results 1 to 2 of 2

Thread: Problem with 00 in array

  1. #1
    Join Date
    Apr 2016
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with 00 in array

    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:

    Code:
    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,

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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):

    Code:
    		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:

    Code:
    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?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Array problem
    By Devilester in forum JavaScript
    Replies: 4
    Last Post: 03-12-2012, 05:17 AM
  2. array problem
    By vividona in forum PHP
    Replies: 10
    Last Post: 03-18-2009, 05:41 AM
  3. array problem
    By motormichael12 in forum PHP
    Replies: 2
    Last Post: 12-30-2006, 08:50 PM
  4. Array Problem...
    By pavmoxo in forum PHP
    Replies: 0
    Last Post: 08-16-2006, 06:05 PM
  5. Replies: 2
    Last Post: 01-13-2006, 05:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •