dimanche 3 décembre 2017

I suck at if statements.

I feel like this is a really dumb question but my brain is fried. Right now I'm working on a very complex set of if and else statements and I'm wondering if there is an easier way? I originally tried or statements but that didn't give me the desired result.

if(fields[0].value === '' && fields[1].value === '' && fields[2].value === '' && fields[3].value === '' ) {
    clusterGroup.addLayer(layer);
} else if(fields[0].value === '' && fields[1].value === city && fields[2].value === '' && fields[3].value === '') {
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === '' && fields[2].value === '' && fields[3].value === '') {
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === city && fields[2].value === '' && fields[3].value === ''){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === '' && fields[1].value === '' && (fields[2].value <= sq && sq != null) && fields[3].value === '') {
    clusterGroup.addLayer(layer);

} else if(fields[0].value === '' && fields[1].value === '' && fields[2].value === '' && (fields[3].value >= sq  && sq != null)) {
    clusterGroup.addLayer(layer);

} else if(fields[0].value === '' && fields[1].value === city && (fields[2].value <= sq && sq != null) && fields[3].value === ''){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === '' && fields[2].value === '' && (fields[3].value >= sq  && sq != null)){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === city && (fields[2].value <= sq && sq != null) && fields[3].value === ''){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === city && fields[2].value === '' && (fields[3].value >= sq  && sq != null)){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === city && (fields[2].value <= sq && sq != null) && (fields[3].value >= sq  && sq != null)){
    clusterGroup.addLayer(layer);
}

Thank you in advanced.

Aucun commentaire:

Enregistrer un commentaire