+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Task 6
+This is the same as Task5, but we need to use a Logical Operator. + As a reminder - here are the requirements again:
+-
+
- If it's less than 50 degrees, wear a coat. +
- If it's less than 30 degrees, wear a coat and hat. +
- If it's less than 0 degrees, stay inside +
- Otherwise, pants and vest are fine. +
+
+
+
+
+
+
+
+
+
+
+
+
+
+function clothesCheckWithLogicalOperator() {
+ var temperature;
+ var dressAdvice;
+ temperature = document.getElementById('temperature').value;
+ if (temperature == "") {
+ return;
+ }
+
+ // All dropdown values are valid numerics so not validating here.
+ var tempC = parseInt(temperature);
+ var dressAdvice;
+
+ // This is a bit more complex than the Task5 solution, but
+ // the checks can be in any order - hence I've moved them around.
+ if (tempC >= 50)
+ dressAdvice = 'Pants and Vest are fine';
+ else if (tempC < 0)
+ dressAdvice = 'Stay Inside';
+ else if (tempC < 30 && tempC >= 0)
+ dressAdvice = 'Wear a Coat and a Hat';
+ else if (tempC < 50 && tempC >= 30)
+ dressAdvice = 'Wear a Coat';
+
+ document.getElementById('dressSense').innerHTML = dressAdvice;
+}
+