Back to Freecodecamp

Challenge 36: Thermostat Adjuster

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68b06e589bf2273243814771.md

latest1.3 KB
Original Source

--description--

Given the current temperature of a room and a target temperature, return a string indicating how to adjust the room temperature based on these constraints:

  • Return "heat" if the current temperature is below the target.
  • Return "cool" if the current temperature is above the target.
  • Return "hold" if the current temperature is equal to the target.

--hints--

adjustThermostat(68, 72) should return "heat".

js
assert.equal(adjustThermostat(68, 72), "heat");

adjustThermostat(75, 72) should return "cool".

js
assert.equal(adjustThermostat(75, 72), "cool");

adjustThermostat(72, 72) should return "hold".

js
assert.equal(adjustThermostat(72, 72), "hold");

adjustThermostat(-20.5, -10.1) should return "heat".

js
assert.equal(adjustThermostat(-20.5, -10.1), "heat");

adjustThermostat(100, 99.9) should return "cool".

js
assert.equal(adjustThermostat(100, 99.9), "cool");

adjustThermostat(0.0, 0.0) should return "hold".

js
assert.equal(adjustThermostat(0.0, 0.0), "hold");

--seed--

--seed-contents--

js
function adjustThermostat(temp, target) {

  return temp;
}

--solutions--

js
function adjustThermostat(temp, target) {
  if (temp < target) {
    return "heat";
  } else if (temp > target) {
    return "cool";
  } else {
    return "hold";
  }
}