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?
switchto make it so much simpler.ifs. (And always using braces, rather than leaving them out sometimes.) No reason for stacking those innerifs, either; us&&.elsedoesn't check a condition, it executes when no previous condition was met. What condition did you expect to be met? What were the values of the variables at that time? Why did you expect the condition to betruewith those values?switch, but I doubt it would be simpler. :-)shirtWidth. Also, from the OP's question, it would appear thatshirtWidthisn't the only criterion, that one has to consider multiple criteria. (That said, I suspect the logic is flawed.)