var ram_price=7.5; // per 2GB var base_vm=700; var sqlstd=12.97; var sqlent=460.15; var windc=25.50; var winstd=3.67;
var cpu_prices = new Array(); cpu_prices["2"]=0; cpu_prices["4"]=300; cpu_prices["6"]=450; cpu_prices["8"]=600;
//Set up an associative array //The keys represent the filling type //The value represents the cost of the filling i.e. Lemon filling is $5,Dobash filling is $9 //We use this this array when the user selects a filling from the form var ram_prices = new Array(); ram_prices["2GB"]=0; ram_prices["4GB"]=2*ram_price; ram_prices["8GB"]=6*ram_price; ram_prices["16GB"]=14*ram_price; ram_prices["32GB"]=30*ram_price; ram_prices["64GB"]=62*ram_price; ram_prices["128GB"]=126*ram_price; ram_prices["256GB"]=254*ram_price; ram_prices["512GB"]=510*ram_price;
// getCakeSizePrice() finds the price based on the size of the cake. // Here, we need to take user's the selection from radio button selection function getCakeSizePrice() { var cakeRadio = document.getElementsByName('selectedcake');
for (i=0; i < cakeRadio.length; i++) {
if (cakeRadio[i].checked) {
user_input = cakeRadio[i].value;
}
}
return cpu_prices[user_input];
}
// getFillingPrice() finds the price based on the filling of the cake.
// Here, we need to take user's the selection from selection list
function getFillingPrice() {
var cakeSelect = document.getElementById('ram');
//alert(filling_prices[cakeSelect.value]);
return ram_prices[cakeSelect.value];
}
function getCandlesPrice() {
var cakeCandles = document.getElementById('includesqlstd');
//var cakeRadio = document.getElementById('
if(cakeCandles.checked) {
if (user_input==2) {
return(2*sqlstd);
}
if (user_input==4) {
return(2*sqlstd);
}
if (user_input==8) {
return(4*sqlstd);
}
} else {
return(0);
}
}
function getSqlEntPrice() {
var vmSQL = document.getElementById('includesqlent');
//var cakeRadio = document.getElementById('
if(vmSQL.checked) {
if (user_input==2) {
return(2*sqlent);
}
if (user_input==4) {
return (2*sqlent);
}
if (user_input==8) {
return (4*sqlent);
}
} else {
return(0);
}
}
function getWinDCPrice() {
var vmWin = document.getElementById('includewindc');
if (vmWin.checked) {
if (user_input==2) {
return(2*windc);
}
if (user_input==4) {
return(2*windc);
}
if (user_input==8) {
return(4*windc);
}
} else {
return (0);
}
}
function getWinStdPrice() {
var vmWinS = document.getElementById('includewinstd');
if (vmWinS.checked) {
if (user_input==2) {
return(0);
}
if (user_input==4) {
return(0);
}
if (user_input==8) {
return(0);
}
} else {
return (0);
}
}
function calculateTotal() {
var total = getCakeSizePrice() + getFillingPrice() + getCandlesPrice() + getSqlEntPrice() + getWinStdPrice() + getWinDCPrice() + base_vm;
var totalEl = document.getElementById('totalPrice');
document.getElementById('totalPrice').innerHTML = "Your Total is: $" + total;
totalEl.style.display = 'block';
}
function hideTotal() {
var totalEl = document.getElementById('totalPrice');
totalEl.style.display = 'none';
}
Last modified 12/2016 Rich Kreider