-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRover.js
91 lines (65 loc) · 2.05 KB
/
Rover.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var nextDir = prompt("Where do you want the Rover to move (N, E, S, W): ");
var myRover = {
position: [4,9],
direction: "N"
};
var marsFloor = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, "R", 0, 0, 0, 0, 0]
];
var yValue = 0;
marsFloor.forEach(function(x){
yValue ++;
if(x.indexOf("R") >= 0){
console.log(`The Rover is currently at X: ${x.indexOf("R")} Y: + ${yValue}`);
var xValue = x.indexOf("R");
yValue = yValue - 1;
console.log(xValue);
console.log(yValue);
return xValue; // Can I return two values? //
}
});
console.log(yValue); //Is yValue changed with if function? //
var currentPosition = [yValue][xValue];
var nextDir = prompt("Where do you want the Rover to move (N, E, S, W): ");
function capitalizeFirstLetter(nextDir) {
return string.charAt(0).toUpperCase();
}
/*
1. Function that actually finds the current position of the Rover.
2. Prompt the user to give the next Direction.
3. For "N"/"S": take current position of Rover and add/substract 1 from the y value.
Draw Array in console with new "R" Position.
For "E"/"W": Do nothing (Rover just rotates).
4.Tell user the new coordinates of Rover.
*/
// marsFloor.forEach(function findRover(x){
// console.log(indexOf("R"));
// }
// function goForward(rover) {
// switch(rover.direction) {
// case "N":
// rover.position[0]++;
// break;
// case "E":
// rover.position[1]++;
// break;
// case "S":
// rover.position[0]--;
// break;
// case "W":
// rover.position[1]--;
// break;
// }
//
// console.log("New Rover Position: [" + rover.position[0] + ", " + rover.position[1] + "]");
// }
// goForward(myRover);