[Solved] Speech is not showing in level Highlander


#1

Hello, I’ve been trying to figure out how to beat the level Highlander in computer science 5. The Hints are confusing to me and I’ve tried to look on the internet for any help, but I couldn’t find anything.
The following is my code for he function, which for some reason doesn’t do anything except make my Hero’s text disappear.
If anyone can help, it would be much appreciated.

function wordInString(string, word) {
    var lenString = string.length;
    var lenWord = word.length;
    // Step through indexes (i) from 0 to (lenString - lenWord)
    for ( var i = 0; i < (lenString - lenWord); i++) {
        // For each of them step through indexes (j) of the word length
        for (var j = 0; j < lenWord; j++) {
            // If [i + j]th letter of the string is not equal [j]th letter of world, then break loop
            if ([i + j] != [j]) {
                break;
            }
            // if this is the last letter of the word (j == lenWord - 1), then return true.
            if (j == lenWord - 1) {
                return true;
            }
    // If loops are ended then the word is not inside the string. Return False.
        }
    }
    return true; // ∆ Remove this when the function is written.
}

#2

Could you pls format your code using 3 backtiks like this ``` then we can help you


#3

Sorry, i’m kind of new to this. How would i do that?


#4

use 3 backticks or there will be an option that looks like this </>


#5

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.


#6

I made an edit to format it


#7

Ok thanks what is the error though


#8

For some reason, it just makes my Hero’s text disappear. Nothing else changes.


#9

You mean that your hero does not say anything?


#10

Yes and no. The hero’s text bubbles have no words, but they still command the soldiers to move to the gate.


#11

then this must be a bug in the level. your code is right as far as i can see


#12

Well ok then. Thank you for your help.


#13

What are you doing here?

            // If [i + j]th letter of the string is not equal [j]th letter of world, then break loop
            if ([i + j] != [j]) {
                break;
            }

Are you comparing letters or only indexes?


#14

But he says that the code is working but the speach bubbles are not showing


#15

Yes, the speech is not showing, and that is all that happens.


#16

I thought that was what the notes wanted me to type.


#17

If [i + j]th letter of the string is not equal [j]th letter of world


#18

So, like this?

 if (lenString[i + j] != lenWord[j]) {
                break;
            }

#19

The function has two parameters…

wordInString(string, word)

#20

So remove the len from string and word then?