Skip to content

Instantly share code, notes, and snippets.

@lexoyo
Last active January 7, 2018 12:09
Show Gist options
  • Save lexoyo/7fb83461d264adfa89063618ff94ec3b to your computer and use it in GitHub Desktop.
Save lexoyo/7fb83461d264adfa89063618ff94ec3b to your computer and use it in GitHub Desktop.
jeff's attempt to the stars
var rover = {
directions : {"N" , "S" , "E" , "W"};
default : "N";
function turnLeft(rover){
console.log("turnLeft was called");
}
function turnRight(rover){
console.log("turnRight was called")
}
function moveForward(rover){
console.log("moveForward was called");
}
function turnLeft(rover){
console.log("direction " + rover.direction);
switch(rover.direction) {
case "N":
console.log("it was N");
rover.direction = "W";
break;
function turnLeft(rover){
console.log("direction " + rover.direction);
switch(rover.direction) {
case "W":
console.log("it was W");
rover.direction = "S";
break;
function turnLeft(rover){
console.log("direction " + rover.direction);
switch(rover.direction) {
case "S":
console.log("it was S");
rover.direction = "E";
break;
function turnLeft(rover){
console.log("direction " + rover.direction);
switch(rover.direction) {
case "E":
console.log("it was E");
rover.direction = "N";
break;
function turnRight(rover){
console.log("direction " + rover.direction);
switch(rover.direction) {
case "N":
console.log("it was N");
break;
function turnRight(rover){
console.log("direction " + rover.direction);
switch(rover.direction) {
case "E":
console.log("it was E");
rover.direction = "S";
break;
function turnRight(rover){
console.log("direction " + rover.direction);
switch(rover.direction) {
case "S":
console.log("it was S");
rover.direction = "W";
break;
function turnRight(rover){
console.log("direction " + rover.direction);
switch(rover.direction) {
case "W":
console.log("it was W");
rover.direction = "N";
break;
function resetLocation() {
self.location = [
(self.location[0,0],
self.location[1,1]
]
}
function move(command) {
var xIncrease = 0, yIncrease = 0;
if (self.direction === "N") {
yIncrease = -1;
} else if (self.direction === "S") {
yIncrease = 1;
} else if (self.direction === "W")
xIncrease = -1;
} else if (self.direction === "E")
xIncrease = 1;
if (command === "f" ) {
xIncrease = 1;
yIncrease = O;
else if (xIncrease = O;
yIncrease = 1;)
}
if (command === "b" ) {
xIncrease = 0;
yIncrease = 1;
else if (xIncrease = 1;
yIncrease = 0;)
}
if (command === "l" ) {
xIncrease = -1;
yIncrease = 0;
}
if (command === "r" ) {
xIncrease = 1;
yIncrease = 0;
}
function multiMoves (commands);
switch (commands: (r,l,f;) {
case "r":
turnRight(rover);
break;
case "l":
turnLeft(rover);
break;
case "f":
moveForward(rover);
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment