[SOLVED] I have a "Convenient Enemy" ;)

 var word = words.length - 1 ;
        // Summon the required unit type.
        hero.summon(word);

I can’t understand how to summon the unit correctly, because if it is

hero.summon(word);

it’s like saying

hero.summon(soldier)

and it should be

hero.summon("soldier")

and if it is

hero.summon("word")

the computer thinks that “word” is a buildType

please help!
—foxfire :fox_face:

word stands for "soldier" quotes and all.

Look again at the instructions:

"words" is an array of words from the "message"

At the moment you’ve written:

var word = words.length - 1 ;

If your variable words is (for example) a sentence made up of 5 words, then this definition means that word = 5 - 1 = 4. In your code at the moment, you’re then trying to summon ‘4’. Is that what you want?

To answer your question, once you define word right then you want hero.summon(word) not hero.summon(“word”), as you want to use the variable you’ve defined.

Jenny

var word = words.length-(words.length-1)

is this the right variable? because I tried it and it doesn’t work … :worried:

Not quite right, but you’re getting closer.

If you wanted the fifth element of the array words, what would you write?

J.

words[4]

but in this level, I don’t know how much words are in the message

Great! And yes you’re exactly right that you don’t know the number of words in the message. So instead of ‘4’ put in ‘words.length-1’, and then the code will work every time.

1 Like

thank you soooooo much!
that solved the problem!
:star_struck:

Well done :grin:.

Jenny

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