Correct Direction based off current direction

What is the one true way to accomplish this? Can you give me an hit

``
// Rover Object Goes Here
// ======================
var rover = [
direction = “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”)
}

switch(rover) {
case turnLeft:
console.log("It’s turning: " + turnleft)
break;
}
``

CONTAINS SMALL SPOILER (how do I code that so it’s fuzzy?)

I agree this is a straightforward simple algorithm, although I’m sure since you are asking it seems neither straightforward, NOR simple.

Javascript aside I’d suggest you start by writing down on a piece of paper, the logic you would use in your own mind to answer the question, and see if you can generalize it so you could start with any direction and receive any turn. Would your solution achieve the correct answer?

If you can do this on paper, you can write what’s called “pseudocode” that represents the programming independant of language. Something like:

-receive starting direction
-receive turn direction
-look up start direction
-find turn direction in table for given start direction
-locate final direction

There are many ways to write the pseudocode or algorithm. Once you can do that, post it here and you will receive better help for getting the Javascript down…although we would liek to see what you can accomplish on your own first. But we could at least help you fidn the correct challenges for your current knowledge.

you’re right @camperextraordinaire but actually I’m getting ready for a programming bootcamp for the next month and this is the last exercise that I have to finish, and same time I’m working on HTML&CSS on freecodecamp too. But you are totally right I know that I have to work on my JavaScript more

AH I was using angled brackets. Thank you!

If I were reviewing bootcamp applicants, and the bootcamp did not expect basic JS knowledge, i would grade this challenge on thinking ability, ie, the pseudocode. Give it a try.

what is the best you to learn about pseudocode?

exactly what I wrote above. Just use plain words (your native language), and write out the steps you would use to solve the problem. Pseudocode is not programming, it is a list of steps for solving a problem, and applies to ANY programming language. Use your native language, which I’m just guessing is not english (based on a few small grammar errors, nothing glaring), and write out how you think you could solve the problem. You don’t need programming experience for this, just think in logical steps and write it out.

1 Like

lovely, thank’s mate

1 Like

This is my code so far, can you guys give me some hit when you have sometime? Thanks a lot, i didn’t wanna open another topic.

``var rover = [
direction = “N”,
position = [0,0],
travelLog = [],
];
// ======================

// ========================
// TURNING LEFT
// ========================
function turnLeft(rover){
console.log(“turnLeft was called!”);
switch(rover) {
case “N”:
rover.direction = “W”
break;
case “W”:
rover.direction = “S”
break;
case “S”:
rover.direction = “N”
break;
case “N”:
rover.direction = “E”
break;
}
}

// ==========================

//======================
// TURNING RIGHT
//======================
function turnRight(rover){
console.log(“turnRight was called!”);
switch(rover) {
case “N”:
rover.direction = “W”
break;
case “W”:
rover.direction = “S”
break;
case “S”:
rover.direction = “N”
break;
case “N”:
rover.direction = “E”
break;
}
}
//========================

// MOVE FORWARD =================
function moveForward(rover){
console.log(“moveForward was called”)
switch(rover.position) {
case “W”:
rover.position[1,0]-- ;
break;
case “N”:
rover.position[0,1]-- ;
break;
case “S”:
rover.position[0,1]++ ;
break;
}
}
// =========================

function receiver() {
for(var i = 0; i < rover.length; i++) {
switch(rover.direction) {
case “f”:
goForward(rover);
break;
case “r”:
turnRight(rover);
break;
case “l”:
turnLeft(rover);
break;
}
}
}
console.log(receiver);

``

This is a great start. I simplified your code some just to do some testing, and this iis mostly your code with a few things cleaned up

(RIght click to open in new window, otherwise without the spoiler tags, it shows a preview)

1 Like

you’ve done it awesome. I’m still having some problems with my code, I guess I need to work little more on it

when I’m trying to add the travelLog to turnRight(); keeps giving me error…
Do you have any idea why?

Hey there, when I’m trying to use the same travelLog to a different function gives me this error, anyone know why? 43%20AM11%20PM

but nobody can see the new post in this section @camperextraordinaire