# Help with lost viking - Javascript

Hello everyone, I hope you are very well! I’m new to the forum and I’ve been playing the game for a day.

I’ve been trying to find a solution for hours, I still don’t understand how to solve this problem, could someone guide me and give me a hand and let me understand how to find the solution at this game level? please

Javascript Code:

``````// You MUST click on the HELP button to see a detailed description of this level!

// The raven will tell you what to use for your maze parameters!

// How many sideSteps north of the Red X you've taken.
var sideSteps = 1;

// How many steps east of the Red X you've taken.
var steps = 1;

// Multiply this with steps to determine your X coordinate. DON'T CHANGE THIS!
var X_PACE_LENGTH = 4;

// Multiply this with sideSteps to determine your Y coordinate. DON'T CHANGE THIS!
var Y_PACE_LENGTH = 6;

// The maze is 35 steps along the X axis.
while(steps <= 35) {

// Take the next step:
hero.moveXY(steps * X_PACE_LENGTH, sideSteps * Y_PACE_LENGTH);

// Increment steps and sideSteps as appropriate, taking into account the special rules.
steps++;
}
``````

This is something difficult to understand…
I do not understand how to solve this problem of the game, could someone give me a hand? I would appreciate it very much, thank you!

Hi and welcome to the forum @Matignacio!
I’m having a hard time deciphering what’s the given code and what’s your code. You have written your code right?

Hello, thanks!
The code given is the one that I have published in this post and I have not written anything, it appears to me that it writes what the crow says,
and what the crow says is:
SLIDE = 10, SWITCH = 7, SKIP = 11

More than that, I don’t know what else to do…

if ur a sub pender can hard cheese this level or use ritic(if u have him) to also HARD cheese the level else idk i cheesed this lvl

I did not understand anything … I still do not understand how to solve this, could someone give me a hand? please…

I’m sorry, but am not a subscriber so I can’t look at my code, and I don’t do JavaScript either.
@Hydrobolic or @abc could help.

1 Like

The first time I completed this level, I hardcoded it (moving the hero manually to each corner), but afterwards I went back and coded it the way you are supposed to (once in python, another time in JS). First, you need to move to (0,0) even if your hero can’t get there. For this level the raven will give you a SLIDE, SWITCH, and SKIP. For each coder it’s different. In your code, you need to define those variables as what the values the raven gives you. My values were 8, 6, and 11. So I defined SLIDE as 8, SWITCH as 6, and SKIP as 11. Next you need to create a new variable (any name you want) and set it to one after you define the three prior variables. I defined mine as temp. Then you want to take a look at the while loop. It should show you this:

``````// The maze is 35 steps along the X axis.
while(steps <= 35) {

// Take the next step:
hero.moveXY(steps * X_PACE_LENGTH, sideSteps * Y_PACE_LENGTH);

// Increment steps and sideSteps as appropriate, taking into account the special rules.
steps++;
}
``````

The incrementation of steps should be at the very end of this while loop, so the code you add should be after the move statement and before the incrementation of steps. The hints guide you through how to complete the level, but you need to replace their values with the values the raven gave you. This part is for the North and South movement of the hero, first (within the while loop), you need to check if steps is divisible by SWITCH (`steps % SWITCH === 0`). If steps is indeed divisible by switch, then you need to multiply and assign (*=) your variable by -1. Since mine was temp, I am going to be using that from now. Then increment sideSteps by temp. After that you need to check if steps is divisible by SKIP. If it is, then increment, or add and assign (+=), sideSteps by temp. This next part is the boundaries of the maze (not getting blown up by fire-traps). You need to check if sideSteps is greater than SLIDE, if it is then subtract and assign (-=) by SLIDE. Next you need to check if sideSteps is less than one, if it is then increment sideSteps by SLIDE. After all that, you need to increment steps (steps++). Although the values are different, you could also do it through the hints in the level.

Hello, I have tried some of what you told me and it worked for me to advance the first line, the problem is the following, I have no idea how to make the next line advance that I show you below in the image, do you think you can help me (keeping my code) and adding to case two of the switch any way to advance in the line marked in the image? please

my javascript code:

``````var steps = 1;
var sideSteps= 1;
var x = 4;
var y = 6;

var c1 = false;
var v1 = 7;

while(true) {
switch(steps < 35)
{
case (steps <= 7 && sideSteps <= 7):
hero.moveXY(steps*4, sideSteps*6);
hero.say("Counting.. " + steps);
break;
case (sideSteps >= 8 && sideSteps <= 8 && c1 === true):
v1 -=1;
hero.moveXY(steps*4, v1*6);
break;
default:
hero.say("You're inside of default...");
}
if (steps == 7 && sideSteps == 7) {
c1 = true;
hero.say("The c1 value is: "+c1);
}
steps +=1;
sideSteps+=1;
}
``````
1 Like

sorry what i mean is for pender use the lightning wand to casl lightningbolt on the nearest burl and go to the bottom right corner than once the fire traps are exploded use haste from elemental codex 5 or 4 and move to the x near the goal and with ritic just do phase shift