forked from LaunchCodeEducation/launchcode.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrover.js
More file actions
59 lines (47 loc) · 1.42 KB
/
rover.js
File metadata and controls
59 lines (47 loc) · 1.42 KB
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
59
class Rover {
constructor(position) {
this.position = position;
this.mode = 'NORMAL';
this.generatorWatts = 110;
}
receiveMessage(message) {
let res = {
message: message.name,
results: []
}
for (const command of message.commands) {
if (command.commandType === 'STATUS_CHECK') {
res.results.push({
completed: true,
roverStatus: {
mode: this.mode,
generatorWatts: this.generatorWatts,
position: this.position
}
});
}
if (command.commandType === 'MODE_CHANGE') {
this.mode = command.value;
res.results.push({
completed: true
});
} else if (command.commandType === 'MOVE') {
if (this.mode === 'LOW_POWER') {
res.results.push({
completed: false
});
} else {
this.position = command.value;
res.results.push({
completed: true
});
}
}
}
return res
}
}
module.exports = Rover;
// set up my test data with different types of tests and messages and recieve the response from the method to see if I have the right structure.
// have to make sure you confirm the process of the item and provide the status of the property in the result array.
// accessed the value in a complex object with the array.