jeudi 30 novembre 2017

JavaScript if/else if/else statement is not working

This is my if/else if/ else statement:

var shirtWidth = 18;
var shirtLength = 33;
var shirtSleeve = 8.63;

// Small Shirts
if(shirtWidth >= 18 && shirtWidth < 20) {
        if(shirtLength >= 28 && shirtLength < 29)
        if(shirtSleeve >= 8.13 && shirtSleeve < 8.38) {
            console.log("S");
        }
}
// Medium Shirts
else if(shirtWidth >= 20 && shirtWidth < 22) {
        if(shirtLength >= 29 && shirtLength < 30)
        if(shirtSleeve >= 8.38 && shirtSleeve < 8.63) {
            console.log("M");
        }
}
// Large Shirts
else if(shirtWidth >= 22 && shirtWidth < 24) {
        if(shirtLength >= 30 && shirtLength < 31)
        if(shirtSleeve >= 8.63 && shirtSleeve < 8.88) {
            console.log("L");
        }
}
// XL Shirts
else if(shirtWidth >= 24 && shirtWidth < 26) {
        if(shirtLength >= 31 && shirtLength < 33)
        if(shirtSleeve >= 8.88 && shirtSleeve < 9.63) {
            console.log("XL");
        }
}
// 2XL Shirts
else if(shirtWidth >= 26 && shirtWidth < 28) {
        if(shirtLength >= 33 && shirtLength < 34)
        if(shirtSleeve >= 9.63 && shirtSleeve < 10.13) {
            console.log("2XL");
        }
}
// 3XL Shirts
else if(shirtWidth === 28) {
        if(shirtLength === 34)
        if(shirtSleeve === 10.13) {
            console.log("3XL");
        }
}
// Does not match any shirt sizes
else {
    console.log("N/A");
}

Everything works except when I get to the else statement at the end. It only works for numbers greater than the 3XL shirts. However, if the numbers are combination of measurements from the 6 categories, the else statement does not print. Does anyone know what I am doing wrong?

Aucun commentaire:

Enregistrer un commentaire