I am new to Javascript and slowing using Apps Scripts by google to practise, firstly, how do assign the value of a global variable to another one depending on if statements. Every test of the code below gives me the last value.
var oneweek = 8640, onefort = 4696, onemonth = 2628, threeweek = 7728, threefort = 4290, threemont = 2401;
var totalprice = 0;
switch (true) {
case (contract_len == "1 Year" && time_len == "Weekly"):
if (day_options == "Full Day") {
var totalprice = oneweek;
}
else {
var totalprice = oneweek / 2;
break;
}
case (contract_len == "1 Year" && time_len == "Fortnightly"):
if (day_options == "Full Day") {
var totalprice = onefort;
}
else {
var totalprice = onefort / 2;
break;
}
case (contract_len == "1 Year" && time_len == "Monthly"):
if (day_options == "Full Day") {
var totalprice = onemonth;
}
else {
var totalprice = onemonth / 2;
break;
}
case (contract_len == "3 Years" && time_len == "Weekly"):
if (day_options == "Full Day") {
var totalprice = threeweek;
}
else {
var totalprice = threeweek / 2;
break;
}
case (contract_len == "3 Years" && time_len == "Fortnightly"):
if (day_options == "Full Day") {
var totalprice = threefort;
}
else {
var totalprice = threefort / 2;
break;
}
case (contract_len == "3 Years" && time_len == "Monthly"):
if (day_options == "Full Day") {
var totalprice = threemont;
}
else {
var totalprice = threemont / 2;
break;
}
}
Is there a way to simplify this? I am using the on Submit form trigger.