the author in silhouette
the author's cat in silhouette

Task 5

This is an extension of Task4. Modify the temperature function so that:

  • 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 clothesCheck() {
  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 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)
      dressAdvice = 'Wear a Coat';
  else if (tempC >= 0)
      dressAdvice = 'Wear a Coat and a Hat';
  else
      dressAdvice = 'Stay Inside';

  document.getElementById('dressSense').innerHTML = dressAdvice;
}