Help with Slalom CS4 Javascript

I did what it told me to do but the code is telling me that it cant read the properties of undefined.

// Use object literals to walk the safe path and collect the gems.
// You cannot use moveXY() on this level! Use move() to get around.
var gems = hero.findItems();

while (hero.pos.x < 20) {
	// move() takes objects with x and y properties, not just numbers.
	hero.move({'x': 20, 'y': 35});
}

while (hero.pos.x < 25) {
	// A gem's position is an object with x and y properties.
	var gem0 = gems[0];
	hero.move(gem0.pos);
}

// While your x is less than 30,
// Use an object to move to 30, 35.
while(hero.pos.x < 30){
    hero.moveXY(30, 35);
}
// While your x is less than 35,
// Move to the position of gems[1].
while(hero.pos.x < 35){
    hero.moveXY(gems[1].pos.x, gems[1].pos.x);
}
// Get to the last couple of gems yourself!
while(hero.pos.x < 25){
    hero.moveXY(gems[2].pos.x, gems[2].pos.y);
}

the message says this:

1 Like

Nvm i just fixed it. i didnt use the right code but here it is:

// Use object literals to walk the safe path and collect the gems.
// You cannot use moveXY() on this level! Use move() to get around.
var gems = hero.findItems();

while (hero.pos.x < 20) {
	// move() takes objects with x and y properties, not just numbers.
	hero.move({'x': 20, 'y': 35});
}

while (hero.pos.x < 25) {
	// A gem's position is an object with x and y properties.
	var gem0 = gems[0];
	hero.move(gem0.pos);
}

// While your x is less than 30,
// Use an object to move to 30, 35.
while(hero.pos.x < 30){
    hero.move({'x': 30, 'y': 35});
}
// While your x is less than 35,
// Move to the position of gems[1].
while(hero.pos.x < 35){
    hero.move({'x': gems[1].pos.x, 'y': gems[1].pos.y});
}
// Get to the last couple of gems yourself!
while(hero.pos.x < 40){
    hero.move({'x': 40, 'y': 35});
}

while(hero.pos.x < 45){
    hero.move({'x': gems[2].pos.x, 'y': gems[2].pos.y});
}

while(hero.pos.x < 50){
    hero.move({'x': 50, 'y': 35});
}

while(hero.pos.x < 55){
    hero.move({'x': gems[3].pos.x, 'y': gems[3].pos.y});
}

1 Like

Hey @27narellano! Welcome to the discourse. Thank you so much for formatting your code correctly :slight_smile:
Good job fixing your code by yourself. However, you should probably delete the correct code since others might copy it and use it for themselves.

Ok bud… :nerd_face: :nerd_face: :nerd_face:

123456789101112

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.