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.
}
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.