I would like to develop a price system based on zip code. now I have only a list of zip code each input but I’d like to have 2 list of zip code. Any ideas?
function checkIfAvailable(zip) {
let zones = ["00182", "00183", "00184", "00185", "00186", "00187", "00153"];
return zones.indexOf(zip) >= 0;
}
function checkIfAvailable(zip1) {
let zone = ["00182", "00183", "00184", "00185", "00186", "00187", "00153"];
return zone.indexOf(zip1) >= 0;
}
function validateZip() {
let zip = document.getElementById("zipCode").value;
let zip1 = document.getElementById("zipCode1").value;
let msg = "";
if (checkIfAvailable(zip) && checkIfAvailable(zip1)) {
msg = "<h2 style='color:green'>Price 1</h2>";
} else {
msg = "<h2 style='color:orange'>Price 2</h2>";
}
document.getElementById("msg").innerHTML = msg;
}
Thank you for your answer.
Really, I want to find the way to do this:
classes of zip:
a) centre of city (00001, 00002, 0003)
b) out of the centre (00004, 00005, 00006)
if I enter two zip code (zip1, zip2) in two input =>
if zip1 and zip 2 are in the centre (a-class) → GREEN AREA
if zip1 is a-class and zip2 is b-class → ORANGE AREA
if zip1 and zip2 are in b-class → RED AREA
if zip1 and zip 2 aren’t in A or B class → BLACK AREA
switch (zip) {
case 00001:
case 00002:
case 00003:
alert("0");
zip = 0;
break;
case 00004:
case 00005:
case 00006:
alert("1");
zip = 1;
break;
case 00007:
case 00008:
case 00009:
alert("2");
zip = 2;
break;
default:
alert("3");
zip = 3;
}
switch (zip1) {
case 00001:
case 00002:
case 00003:
alert("0");
zip1 = 0;
break;
case 00004:
case 00005:
case 00006:
alert("1");
zip1 = 1;
break;
case 00007:
case 00008:
case 00009:
alert("2");
zip1 = 2;
break;
default:
alert("3");
zip1 = 3;
}
function validateZip() {
let zip = document.getElementById("zipCode").value;
let zip1 = document.getElementById("zipCode1").value;
let msg = "";
if (zip == zip2) {
msg = "<h2 style='color:green'>You spend 1€</h2>";
} else if (zip > zip2) {
msg = "<h2 style='color:orange'>You spend 2€</h2>";
} else if (zip < zip2) {
msg = "<h2 style='color:orange'>You spend 2€</h2>";
} else {
msg = "<h2 style='color:orange'>Boom!</h2>";
}
document.getElementById("msg").innerHTML = msg;
}