-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path11-6-HeatingPlan.js
58 lines (49 loc) Β· 967 Bytes
/
11-6-HeatingPlan.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* p437 μμ
*/
class HeatingPlan {
#min;
#max;
constructor(min, max) {
this.#min = min;
this.#max = max;
}
targetTemparature(selectedTemperature) {
if (selectedTemperature > this.#max) return this.#max;
else if (selectedTemperature < this.#min) return this.#min;
else return selectedTemperature;
}
}
/**
* μμ μ€νμ μν μμμ μ½λ
*/
const thermostat = {
selectedTemperature: 24,
currentTemperature: 17,
};
const thePlan = new HeatingPlan(0, 25);
function setToHeat() {
console.log('set to heat');
}
function setToCool() {
console.log('set to cool');
}
function setOff() {
console.log('set off');
}
/**
* μμ νΈμΆ
*/
if (
thePlan.targetTemparature(thermostat.selectedTemperature) >
thermostat.currentTemperature
) {
setToHeat();
} else if (
thePlan.targetTemparature(thermostat.selectedTemperature) <
thermostat.currentTemperature
) {
setToCool();
} else {
setOff();
}