We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f31e24a commit b18e135Copy full SHA for b18e135
1 file changed
Codecademy/gettersAndSetters.js
@@ -0,0 +1,23 @@
1
+const robot = {
2
+ _model: "1E78V2",
3
+ _energyLevel: 100,
4
+ _numOfSensors: 15,
5
+ get numOfSensors() {
6
+ if (typeof this._numOfSensors === "number") {
7
+ return this._numOfSensors;
8
+ } else {
9
+ return "Sensors are currently down.";
10
+ }
11
+ },
12
+ set numOfSensors(num) {
13
+ if (typeof num === "number" && num >= 0) {
14
+ this._numOfSensors = num;
15
16
+ console.log("Pass in a number that is greater than or equal to 0");
17
18
19
+};
20
+
21
+console.log(robot.numOfSensors);
22
+robot.numOfSensors = 100;
23
0 commit comments