Hi there,
I was stuck at this level for days. Even with your explenation @Harry_the_Wanderer I just didn’t get it.
But just now I found the answer to the Level, the console Log helped a lot.
The problem is (j == lenWord - 1). The j is also part of the lenWord - 1 part.
I hope this hint helps.
And thanks to Harry for so much afford I appreciate that.
@Tobias_Kreuzig you are welcome. I wanted to help everyone work “through” the problem and not just copy-cut-paste.
[quote="Ninja_Emboar, post:26, topic:9220"]
```python
for i in range(lenString - lenWord)
```
[/quote]
@Ninja_Emboar so there are several things happening here.
Do you understand for loops and their purpose?
Do you understand the range() function
Do you understand the purpose behind the mathematics involved with the calculation lenString - lenWord
here is your above code example. somehow when I copied it the brackets were off, and obviously variables weren’t declared. This here can be copied straight to console (for example in chrome developer tools, by pressing F12 or right click -> “inspect”) to see the log in action
var string = "macaffe", word = "affe", lenString = string.length, lenWord = word.length;
console.log("====== name : " + string + " word: " + word);
for ( var i = 0; i < lenString; i++) {
console.log("============= Outer Loop: i= " + i);
for (var j = 0; j < lenWord; j++) {
console.log("Inner loop: i = " + i + " j = " + j + " (i + j) = " + (i + j) + " string[i]: " + string[i] + " string[i+j]:" + string[i+j] + " word[j]; " + word[j] + " word[lenWord -1]: " + word[lenWord - 1] );
if (string[i] == word[lenWord - 1]) {
console.log("======= Matched string[i] to word[2]");
}
}
}