My code does not work!


Oops, try again. There was a problem with your syntax.

var text = "Hey, I'm Amber. Amber means beautiful rock \ or something like that.";
var myName = "Amber";
var hits = []

for ( i = 0; i < text.length; i++){
    if (text[i] === 'A') {
        for (var l = i; l < i + myName.length; l++) {


if (hits.length = 0) {
    console.log("Your name wasn't found!");


Never mind!!! I had 1 too many curly braces :smiley:


Your second for loop will go over your name letter by letter, which results in a lot of hits in your case, for each instance of your name, you push 5 ambers into your hits array. You could also do:

for (var l = i; l < i + myName.length; l++) {

l will hold the index of the a letter of your name while it run, and by using this number to access your text variable, you can push the letters into your hits array, one by one


I don't understand of writing this code.Would you explain in simple words?


I did wrote two if not more extensive explanations of the second for loop, have you read those? Read those, or of someone else, and then you can come for a specific question, such answers are very time consuming