Continuous Alchemy (javascript)


#1

I spent a really long time on this level, but my character never moves. I think it is something about the if poison line. This is in javascript. Please help me!


#2

This is my code right now.

// Race munchkins to the water distilled by Omarn Brewstone!
// The continue statement is powerful for managing complicated logic.
// When the program uses the continue statement, the rest of the loop is skipped.
// However, unlike with “break”, the loop repeats instead of stopping.
// Use “continue” to verify the conditions of the ambush.
loop {
var enemy = this.findNearestEnemy();
var item = this.findNearestItem();

// If there is no enemy, continue out of the loop.
if(!enemy) {
    continue;
}
// If there is an enemy, but no item, ask for a potion and continue out of the loop.
if(!item) {
    this.say("Give me a drink!");
    continue;
}
// Use an if-statement to check the item's type. If the type is "poison", continue out of the loop.
 if ("poison") {
    continue; 
    }

// If it is not, the potion must be a bottle of water, so walk to it and return to the starting position!
else {
this.moveXY(44, 36);
this.moveXY(34, 47);
}
}


#3

Before continuing to read this post, please read the FAQ to learn how to format your code.

You are checking the item’s type wrong. You check it with item.type.

if (item.type === ...) {

#4

Thank you! That worked! I will also check the FAQ. Thanks!!!


#5

need hepl here is my code all it says is that I nee this.pos
// Race munchkins to the water distilled by Omarn Brewstone!
// The continue statement is powerful for managing complicated logic.
// When the program uses the continue statement, the rest of the loop is skipped.
// However, unlike with “break”, the loop repeats instead of stopping.
// Use “continue” to verify the conditions of the ambush.
loop {
var enemy = this.findNearestEnemy();
var item = this.findNearestItem();

// If there is no enemy, continue out of the loop.
if(!enemy) {
    continue;
}

this.say("I see an enemy");
// If there is an enemy, but no item, ask for a potion and continue out of the loop.
if(!item) {
    this.say("Give me a drink!");
    continue;
}
//e an if-statement to check the item's type. If the type is "poison", continue out of the loop.
if (item.type === poison) {
 this.say("it is poison");   
} else if (item.type === water) {
    this.moveXY(44, 36);
    this.moveXY(34, 47);
}

}


#6

DrTerror_Joseph I think i have told you this before but please format your code according to the discourse FAQ.