samedi 5 janvier 2019

Air conditioner function

I have a problem. I'm beginner at Javascipt and there is one problem that I can't solve. " An air conditioner has a built-in thermometer that measures the room temperature. When the user enters the desired temperature into the remote control, it starts working, but its fan speed depends on the difference between the actual temperature and the desired temperature. If the difference is bigger than 10 degrees, the fan’s speed is 3x, if it is bigger than 5 but less than or equal to 10, fan speed is 2x, and between 0 and 5 degrees, fan speed is 1x. Write a JavaScript function to simulate the air conditioner" This is the problem. And I wrote code below but it returns 1x for every number I tried. Can you help me please?

function airConditioner(aT, dT) {
                var difference = function (aT , dT) { 
return Math.abs(aT-dT); }
if (difference > 10) {
  return "3x";
} 
else if (difference < 10) {
  return "2x";
} 
else if (5 < difference || difference < 10) {
  return "2x";
} 

else { 0 < difference || difference < 5
  return "1x";
}
        }
        airConditioner(19, 15);
  

Aucun commentaire:

Enregistrer un commentaire