From 56792d403826bad65a520ff1699c489d9b08a7d9 Mon Sep 17 00:00:00 2001 From: Craig Richards Date: Thu, 11 Mar 2021 16:34:56 +0000 Subject: [PATCH] Task 6 temperature algorithm with logical operator --- index.html | 3 + js/complexTemp.js | 25 +++++++ js/moreTemp.js | 3 +- task1.html | 3 + task2.html | 3 + task3.html | 3 + task4.html | 3 + task5.html | 6 +- task6.html | 184 ++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 231 insertions(+), 2 deletions(-) create mode 100644 js/complexTemp.js create mode 100644 task6.html diff --git a/index.html b/index.html index e369caa..8ae4c84 100644 --- a/index.html +++ b/index.html @@ -40,6 +40,9 @@ + diff --git a/js/complexTemp.js b/js/complexTemp.js new file mode 100644 index 0000000..7b4a130 --- /dev/null +++ b/js/complexTemp.js @@ -0,0 +1,25 @@ +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; +} diff --git a/js/moreTemp.js b/js/moreTemp.js index d30e2af..56774ee 100644 --- a/js/moreTemp.js +++ b/js/moreTemp.js @@ -10,7 +10,8 @@ function clothesCheck() { var tempC = parseInt(temperature); var dressAdvice; - // The Zen of Python point 5: Flat is better than nested... + // This is a simple solution, but it depends on the tests being in + // the correct sequence. if (tempC >= 50) dressAdvice = 'Pants and Vest are fine'; else if (tempC >= 30) diff --git a/task1.html b/task1.html index db535f1..a6f9b11 100644 --- a/task1.html +++ b/task1.html @@ -40,6 +40,9 @@ + diff --git a/task2.html b/task2.html index dcc239c..3edd425 100644 --- a/task2.html +++ b/task2.html @@ -40,6 +40,9 @@ + diff --git a/task3.html b/task3.html index e686714..14f92e2 100644 --- a/task3.html +++ b/task3.html @@ -40,6 +40,9 @@ + diff --git a/task4.html b/task4.html index d6d7401..af2c22e 100644 --- a/task4.html +++ b/task4.html @@ -40,6 +40,9 @@ + diff --git a/task5.html b/task5.html index 4ca72db..b5eee73 100644 --- a/task5.html +++ b/task5.html @@ -40,6 +40,9 @@ + @@ -141,7 +144,8 @@

Task 5

var tempC = parseInt(temperature); var dressAdvice; - // The Zen of Python point 5: Flat is better than nested... + // This is a simple solution but it depends on the tests being in + // the correct sequence. if (tempC >= 50) dressAdvice = 'Pants and Vest are fine'; else if (tempC >= 30) diff --git a/task6.html b/task6.html new file mode 100644 index 0000000..cd0de13 --- /dev/null +++ b/task6.html @@ -0,0 +1,184 @@ + + + + + + Functions and Control Flow + + + + + + + + + + +
+ +
+ +
+
+ the author in silhouette +
+
+ the author's cat in silhouette +
+
+ +
+
+

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.
  • +
+ + +
+
+
+
+ + +
Please select the temperature
+
+
+ +
+
+ +
+
+

+
+
+ + +
+
+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;
+}
+
+
+
+
+ +
+ + + + + + +