Total Price Estimate Based on Drop Downs and Multiple Selects
-
I want to get a total price estimate for a painting and decorating calculator. The base value is 300 for a one-off job with added rooms or extras. However none of the sums are showing up.
This is what I have for coding however it’s not working; Any advice?
(function(){
// Base amount
var baseAmount = 300;
var totalPrice = baseAmount;
// Get field values
var bedrooms = getField('fieldname16').val();
var bathrooms = getField('fieldname47').val();
var propertyType = getField('fieldname18').val();
var occupied = getField('fieldname17').val();
var additionalRooms = getField('fieldname20').val();
var extraPainting = getField('fieldname21').val();
var doors = getField('fieldname25').val();
var windows = getField('fieldname29').val();
var repairs = getField('fieldname22').val();
var congestionZone = getField('fieldname44').val();
var parkingAvailable = getField('fieldname45').val();
// Calculate bedrooms cost
var bedroomPrices = {
"0 Bedroom": 0,
"1 Bedroom": 0,
"2 Bedroom": 120,
"3 Bedroom": 260,
"4 Bedroom": 450,
"5 Bedroom": 630,
"6 Bedroom": 800
};
totalPrice += bedroomPrices[bedrooms];
// Calculate bathrooms cost
var bathroomPrices = {
"0 bathroom": 0,
"1 bathroom": 130,
"2 bathroom": 250,
"3 bathroom": 350
};
totalPrice += bathroomPrices[bathrooms];
// Calculate property type cost
var propertyPrices = {
"Flat": 0,
"Terrace": 0,
"Semi-Detached": 50,
"Detached": 50,
"Other": 0
};
totalPrice += propertyPrices[propertyType];
// Calculate occupied cost
var occupiedPrices = {
"Yes": 50,
"No": 0
};
totalPrice += occupiedPrices[occupied];
// Calculate additional rooms cost
var additionalRoomPrices = {
"Living Room": 180,
"Kitchen": 110,
"Bathroom": 110,
"Hallway": 150,
"Stairwell & Landing": 140
};
if (additionalRooms) {
for (var i = 0; i < additionalRooms.length; i++) {
totalPrice += additionalRoomPrices[additionalRooms[i]];
}
}
// Calculate extra painting cost
var numBedrooms = parseInt(bedrooms.charAt(0)) || 0;
var numBathrooms = parseInt(bathrooms.charAt(0)) || 0;
var ceilingCost = 80 * (numBedrooms + (additionalRooms ? additionalRooms.length : 0) + numBathrooms);
var skirtingBoardCost = 40 * (numBedrooms + (additionalRooms ? additionalRooms.length : 0) + numBathrooms);
var extraPaintingCosts = {
"Ceiling": ceilingCost,
"Skirting Board": skirtingBoardCost
};
if (extraPainting) {
for (var j = 0; j < extraPainting.length; j++) {
totalPrice += extraPaintingCosts[extraPainting[j]];
}
}
// Calculate doors cost
totalPrice += 45 * parseInt(doors);
// Calculate windows cost
totalPrice += 35 * parseInt(windows);
// Calculate repairs cost
var repairPrices = {
"No repairs": 0,
"small repairs": 50,
"medium repairs": 110,
"major repairs": 220
};
totalPrice += repairPrices[repairs];
// Calculate congestion zone cost
var congestionZonePrices = {
"Yes": 15,
"No": 0
};
totalPrice += congestionZonePrices[congestionZone];
// Calculate parking available cost
var parkingPrices = {
"Yes": 0,
"No": 15
};
totalPrice += parkingPrices[parkingAvailable];
return totalPrice;
})()The page I need help with: [log in to see the link]
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- You must be logged in to reply to this topic.