[SOLVED] Help: the hunt begins

help i cant do this

[en_US.composer.my_button_text]

But he doesn’t know how big a Burleous Majoris would be…

Find the average size of this burl population to use as a baseline!

This function returns average size of all the burls in an array.

def averageSize(burls):
sum = sumSize(burls)
# Remember the average is the sum of the parts divided by the amount!
return sum / burls.length

This function should return the sum of all the burls sizes.

def sumSize(burls):
# Implement the sum function using the burls ‘size’:
burlHealth = 0
enemies = hero.findEnemies()
for burls in enemies:
burlHealth += burl.health

while True:
# Find the average size of the burls by calling the ‘averageSize’ function

averageSize()
# Say the average size of the seen burls!
hero.say(averageSize)

Welcome to the Codecombat discourse.

This is the important line here. ‘size’ would translate to object.size, not object.health.
And when you use the averageSize() function in the while true loop, you need to set it to a variable then say the variable. e.g. myName = getMyName(hero.findNames()) hero.say(myName)
I hope this helps.

1 Like

it has an error
it says: TypeError: Cannot read ‘property’ length of undefined

Make sure you put the ‘burls’ array in the brackets of the averageSize() function, otherwise you checking the averageSize of nothing.

1 Like

this is my code:

This function returns average size of all the burls in an array.

def averageSize(burls):
sum = sumHealth(burls)
# Remember the average is the sum of the parts divided by the amount!
enemies = hero.findEnemies()
for burl in enemies:
return sum / burls.length

This function should return the sum of all the burls sizes.

def sumHealth(burls):
# Implement the sum function using the burls ‘size’:
burlHealth = 0
enemies = hero.findEnemies()
for burl in enemies:
burlHealth += burl.health
return burlHealth

while True:
# Find the average size of the burls by calling the ‘averageSize’ function

averageSize()
# Say the average size of the seen burls!
hero.say(averageSize)

how do i format my code

Look at this topic: link, for formatting.

you still haven’t changed this section. Reread my posts above and see if you can figure it out.

1 Like

my new code

def averageSize(burls):
    sum = sumHealth(burls)
    # Remember the average is the sum of the parts divided by the amount!
    burls = hero.findByType("burl")
    for burl in burls:
        return sum / burls.length

def sumHealth(burls):
    # Implement the sum function using the burls 'size':
    burlHealth = 0
    enemies = hero.findEnemies()
    for burl in enemies:
        burlHealth += burl.health
        return burlHealth
        

while True:
    
    
    averageSize()
    # Say the average size of the seen burls!
    hero.say(averageSize)]

can you please show me a link for your posts

my hero says: [Function averageSize]

My posts are the ones above in this topic, ah well, I’ll tell you again.
Your problem’s still here:

look at this function:
averageSize() It needs to have something in the brackets () to use here:

You can use an array. e.g. hero.findEnemies(), you would put that value into a variable (enemies = hero.findEnemies()) then put that value into a function: damage = totalDamage(enemies).
Do you understand now?

1 Like

# But he doesn't know how big a Burleous Majoris would be...
# Find the average size of this burl population to use as a baseline.

# This function returns average size of all the burls in an array.
def averageSize(burls):
    sum = sumHealth(burls)
    # Remember the average is the sum of the parts divided by the amount!
    burls = hero.findByType("burl")
    for burl in burls:
        return sum / burls.length

# This function should return the sum of all the burls sizes.
def sumHealth(burls):
    # Implement the sum function using the burls 'size':
    burlHealth = 0
    enemies = hero.findEnemies()
    for burl in enemies:
        burlHealth += burl.health
        return burlHealth
        

while True:
    # Find the average size of the burls by calling the 'averageSize' function
    enemies = hero.findEnemies()
    burls = hero.findByType("burls")
    burls = averageSize(burls)
    averageSize(burls)
    
    # Say the average size of the seen burls!
    hero.say(averageSize)

never mind i solved it

Hello. Can anyone please help me? I’m stuck on this level as well.

// Senick is trying to find the elusive Burleous Majoris!
// "But he doesn't know how big a Burleous Majoris would be..."
// Find the average size of this burl population to use as a baseline!

// This function returns average size of all the burls in an array.
function averageSize(burls) {
    var sum = sumSize(burls);
    // Remember the average is the sum of the parts divided by the amount!
    return sum / burls.length;
}

// This function should return the sum of all the burls sizes.
function sumSize(burls) {
    // Implement the sum function using the burls 'size':
    var sum = 0;
    for (var i = 0; i < burls.length; i++) {
        var burl = burls[i];
        var health = burl.health;
        sum = sum + health;
    }
    return sum;
}

while(true) {
    // Find the average size of the burls by calling the 'averageSize' function.
    var burls = hero.findEnemies();
    hero.say(averageSize(burls));
    // Say the average size of the seen burls!
}

In your averageSize function, you are calling your other function, but are not defining the object this other function needs to work with.

Also, in your second function, take a closer look at this comment:

    // Implement the sum function using the burls 'size':

You need to adjust your code accordingly.

1 Like

this is my code can you help me?

# But he doesn't know how big a Burleous Majoris would be...
# Find the average size of this burl population to use as a baseline.

# This function returns average size of all the burls in an array.
def averageSize(burls):
    sum = sumHealth(burls)
    # Remember the average is the sum of the parts divided by the amount!
    burls = hero.findByType("burl")
    for burl in burls:
        return sum / burls.length

# This function should return the sum of all the burls sizes.
def sumHealth(burls):
    # Implement the sum function using the burls 'size':
    burlHealth = 0
    enemies = hero.findEnemies()
    for burl in enemies:
        burlHealth += burl.health
        return burlHealth
        

while True:
    # Find the average size of the burls by calling the 'averageSize' function
    enemies = hero.findEnemies()
    burls = hero.findByType("burls")
    burls = averageSize(burls)
    averageSize(burls)
    
    # Say the average size of the seen burls!
    hero.say(averageSize)

You should return this after the for loop is over.

Andrei

thank you very much @AnSeDra i got it

1 Like

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