Feedback: Deja Brew

This is my code:

potionsOnTheWall = 10
numToTakeDown = 1
while True:
self.say(potionsOnTheWall + " potions of health on the wall!")
# Sing the next line:
self.say(potionsOnTheWall + " potions of helth!")
# Sing the next line:
self.say(“Take " + numToTakeDown + " down, pass it around!”)
potionsOnTheWall -= numToTakeDown
# Sing the last line:
self.say(potionsOnTheWall + " potions of health on the wall.")

And my code does not work. An error in the 5 iteration. What am I doing wrong?
Thaks

@Debash Looks like you have a typo: “helth” should be “health”.

1 Like

potionsOnTheWall = 10
numToTakeDown = 1
loop:
self.say(potionsOnTheWall + " potions of health on the wall!")
self.say(potionsOnTheWall + " potions of health!")
self.say(“Take " + numToTakeDown + " down, pass it arround!”)
potionsOnTheWall -= numToTakeDown
self.say(potionsOnTheWall + " potions of health on the wall.")

What`s wrong here ?

@Lokusama You have a typo: “arround” should be “around”.

Thank you very much!!!

what am i doing wrong anybody have a code i can borrow that is javascript

loop {
var potionsOnTheWall = 10;
var numToTakeDown = 1;

this.say(potionsOnTheWall + " potions of health on the wall!");
this.say(potionsOnTheWall + " potions of health!");
this.say(“Take " + numToTakeDown + " down, pass it around!”);
potionsOnTheWall -= numToTakeDown;
this.say(potionsOnTheWall + " potions of health on the wall.");
}

@Jaydon_Tillitson the var declarations should be outside of the loop, otherwise you would always have the same values on every iteration.

Additionally , I believe the -= function is specific to Python. I could be wrong, however.

JavaScript also has a -= operator. See Subtraction assignment - MDN.

JavaScript has compound assignment operators (+=, -=, *=, /=) as well as increment/decrement operators (++, --). Python has compound assignment operators but no increment/decrement operators.

ok thank you very much

Im using LUA and i have no idea how to get the loop to work correctly and decrease the number of potions. Can anyone help?

maybe post your code first? So we know what’s wrong.

anyone can help me with the code

local potionsOnTheWall = 10
local numToTakeDown = 1
local numero = potionsOnTheWall - numToTakeDown
loop
self.say (potionsOnTheWall + “! pociones de salud en la pared”)
–Canta la siguiente línea:
self.say (potionsOnTheWall + “! pociones de helth”)
–Canta la siguiente línea:
self.say ( “Take” + numToTakeDown + “hacia abajo, pasarlo alrededor!”)
potionsOnTheWall - = numToTakeDown
–anta la última línea:
self.say (potionsOnTheWall + “pociones de salud en la pared.”)
end

LUA does not allow for the -= or += decrement/increment shortcuts.

This means

potionsOnTheWall -= numToTakeDown

won’t work. You’ll need to do a little more typing:

potionsOnTheWall = potionsOnTheWall - numToTakeDown

Maka

potionsOnTheWall = 10
numToTakeDown = 1
while True:
hero.say(potionsOnTheWall + " potions of health on the wall!")
# Sing the next line:
hero.say(potionsOnTheWall + " potions of health!")
# Sing the next line:
hero.say(potionsOnTheWall + " Take Y down, pass it around!")
potionsOnTheWall -= numToTakeDown
# Sing the last line:
hero.say(potionsOnTheWall + " X-Y potions of health on the wall")

What´s wrong here???
Help me please.

potionsOnTheWall = 10
numToTakeDown = 1
while True:
hero.say(potionsOnTheWall + " potions of health on the wall!")
# Sing the next line:
hero.say(potionsOnTheWall + “potions of health”)
# Sing the next line:
hero.say(“take” + numToTakeDown + "down, pass it around!"
potionsOnTheWall -= numToTakeDown
# Sing the last line:
hero.say(potionsOnTheWall + “potions of health on the wall.”

中国译名:各位,请记得按话语FAQ格式化你的代码。

English translation:

Everybody, please remember to format your code according to the discourse FAQ.

Why X and Y? this code has some errors. if you read it carefully, you should be able to get it.

I don’t know what I am doing wrong.

potionsOnTheWall = 10
numToTakeDown = 1
while True:
    hero.say(potionsOnTheWall + " potions of health on the wall!")
    # Sing the next line:
    hero.say(potionsOnTheWall + " potion of health!")
    # Sing the next line:
    hero.say("Take " + numToTakeDown + " down, pass it around!")
    potionsOnTheWall -= numToTakeDown
    # Sing the last line:
    hero.say(potionsOnTheWall + " potions of health on the wall.")

Please learn to post your code properly. It’s really easy and only requires a very small amount of effort.

To post your code from the game, use the </> button or it won’t format properly. When you click the </> button, the following will appear:

Please paste ALL of your code inside the triple back tick marks.

``` <— Triple back tick marks.

Paste ALL of your code in here.

``` <— Triple back tick marks.

There are many people here willing and able to help. If you use the </> button correctly, then ALL of your code should look like this:

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    else:
        hero.say("My code is formatted properly")

If ALL of your code isn’t formatted like the code above, then you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well.

Thank you.