# Correct Direction based off current direction

Correct Direction based off current direction
0

#1

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;
}
``

Using same long gives me error
#2

If you are having trouble solving these types of challenges, you should strongly consider working through the FCC JavaScript sections of the curriculum. You will learn a whole lot about JavaScript and these types of challenges will be a very easy to solve. Start with the Basic JavaScript section and continue through all the JavaScript Algorithms And Data Structures lessons.

#3

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
-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.

#4

Wrap the code in spoiler tags `[spoiler]` and `[/spoiler]`

#5

you’re right @RandellDawson 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

#6

AH I was using angled brackets. Thank you!

#7

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.

#8

what is the best you to learn about pseudocode?

#9

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.

#10

lovely, thank’s mate

#11

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;
}
}
// =========================

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;
}
}
}

``

#12

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)

#13

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

#14

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

#15

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

#16

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

#17

Yes they can. It shows up just fine.