Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts

    groupstring help

    Ok, got an odd problem, cant seem to figure out what ive done wrong, It all ways unless days > 84, the it just shows Nan?


    any ideas ??

    Code:
    // price calculation
    function calculate() {
    	// use get month 
        var month = new Date().getMonth();
    
         var d1 = document.date.firstDate.value;
         var d2 = d1.replace(/^(\d{1,2}\/)(\d{1,2}\/)(\d{4})$/, "$2$1$3");
         var d3 = new Date(d2);
    month = d3.getMonth();
    
    		var days = parseInt('0' + document.date.days.value, 10),
    			groupstring, total = 0;
    // 1 day, 2 days, 3 days, 4 days, 5 days, 6 days, 7 days, 28 DaySummer, 28 DayWinter, Excess Amount, excess mile
    		switch (document.date.car.value) {
    			
    			case 'B': groupstring = '2650,5300,7950,10600,13250,13500,14500,48000,46000,25000,10,440';  break;//CLIO 3/5 -->
    			case 'B2': groupstring = '2650,5300,7950,10600,13250,13500,14500,48000,46000,25000,10,440';  break;//MAN PICANTO -->
    			case 'CD': groupstring = '2800,5600,8400,11200,14000,14500,15500,49900,48000,25000,10,460';  break;// RIO MANUAL-->
    			case 'CD2': groupstring = '2800,5600,8400,11200,14000,14500,15500,49900,48000,25000,10,460';  break;//CORSA -->
    			case 'CD3': groupstring = '2800,5600,8400,11200,14000,14500,15500,49900,48000,25000,10,460';  break;// PICANTO AUTO-->
                case 'CD4': groupstring = '2800,5600,8400,11200,14000,14500,15500,49900,48000,25000,10,440';  break;// 500-->
    			case 'E': groupstring = '3000,6000,9000,12000,15000,15500,16500,53500,51000,25000,10,440';  break;// VENGA MANUAL -->
    			case 'E2': groupstring = '3000,6000,9000,12000,15000,15500,16500,53500,51000,25000,10,480';  break;// RIO AUTO-->
    			case 'F': groupstring = '3200,6400,9600,12800,16000,17000,17500,58000,54000,25000,15,440';  break;// FOCUS-->
    			case 'F2': groupstring = '3200,6400,9600,12800,16000,17000,17500,58000,54000,25000,15,440';  break;// MEGANE-->
    			case 'F3': groupstring = '3200,6400,9600,12800,16000,17000,17500,58000,54000,25000,15,480';  break;// CEED-->
    			case 'F4': groupstring = '3200,6400,9600,12800,16000,17000,17500,58000,54000,25000,15,440';  break;// I30-->
    			case 'F5': groupstring = '3200,6400,9600,12800,16000,17000,17500,58000,54000,25000,15,500';  break;// VENGA AUTO-->
    			case 'G': groupstring = '3500,7000,10500,14000,17500,19000,20000,62000,59000,25000,15,540'; break;//CEED ESTATE -->
    			case 'G2': groupstring = '3500,7000,10500,14000,17500,19000,20000,62000,59000,40000,15,540'; break;//SPORT PET -->
    			case 'H': groupstring = '3800,7600,11400,15200,19000,21500,22500,72000,62000,25000,15,440'; break;// -MONDEO->
    			case 'I': groupstring = '3800,7600,11400,15200,19000,21500,22500,72000,62000,25000,15,580'; break;//2WD SPORTAGE -->
    			case 'J': groupstring = '4500,9000,13500,18000,22500,24000,25000,75000,65000,40000,15,600'; break;//4WD SPORTAGE -->
    			case 'J2': groupstring = '4500,9000,13500,18000,22500,24000,25000,75000,65000,40000,15,440'; break;//OPTIMA -->
    			case 'J3': groupstring = '5000,9000,13500,18000,22500,24000,25000,75000,65000,40000,15,440'; break;//IX35 -->
    			case 'K': groupstring = '6500,11000,16500,22000,27500,30000,31000,95000,82500,40000,15,440'; break;//GALAXY -->
    			case 'K2': groupstring = '6500,11000,16500,22000,27500,30000,31000,95000,82500,40000,15,440'; break;//RCZ -->
    			case 'L': groupstring = '7000,12000,18000,24000,30000,35000,36000,120000,120000,40000,15,1000'; break;// SORENTO-->
    			case 'L2': groupstring = '7000,12000,18000,24000,30000,35000,36000,120000,120000,40000,15,1000'; break;// I800-->
    			case 'L3': groupstring = '4500,9000,13500,18000,22500,24000,25000,75000,65000,40000,15,600'; break;//carens -->
    			case 'M': groupstring = '2650,5300,7950,10600,13250,14600,15000,49900,48000,25000,10,440'; break;// KANGOO-->
    			case 'N': groupstring = '2800,5600,8400,11200,14000,14500,15500,49900,48000,25000,10,460'; break;// nv200-->
    			case 'O': groupstring = '4100,8200,12300,16400,20500,20800,21000,70000,70000,40000,15,625'; break;// TRAFIC-->
    		}
    		groupstring = groupstring.split(',');
    		if (days > 0 && days < 8) {total =  groupstring[days - 1];     } else
    		if (days < 28)            {total = (groupstring[6] / 7) * days;} else
    		if (days === 28)          {total =  groupstring[8];}
    		if (days > 28)   		  {total =(groupstring[8] / 28) * days;}
    		if (month > 1 && month < 9 && days == 28) {total = groupstring[7];} // if jan or feb or oct, nov, dec then summer
    		if (month > 1 && month < 9 && days > 28) {total =(groupstring[7] / 28) * days;}
    		if (days > 84)   		  {total =(groupstring[12] / 28) * days;}
    	var testa = parseInt(groupstring[8])
    	var testb = parseInt(groupstring[7])
    
    	
    	    
    if (days < 28 && total > testa && month < 2 ) {total = groupstring[8]} // winter
    if (days < 28 && total > testa && month > 8 ) {total = groupstring[8]} // winter
    if (days < 28 && total > testb && month > 1 && month < 9 ) {total = groupstring[7]} // summer
    				
    				
    				
    				
    				
    		
    	
    			document.date.rentalamount.value = "£" + (Math.round(total) / 100).toFixed(2);
    
    		}

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,597
    Thanks
    23
    Thanked 646 Times in 645 Posts
    This stands out:
    var days = parseInt('0' + document.date.days.value, 10), groupstring, total = 0;
    And FYI Number() is normally a better choice than parseInt().
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    LinkBacks (?)

    1. 03-08-2014, 07:09 PM

    Posting Permissions

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