Can't seem to figure this out?!


#1

Hello all, I've tried editing my existing code with solutions found on the Forums, but nothing will work :frowning: And I'm pretty sure I've edited everything correctly :confused: Could someone help me?

This is Exercise 5 ("Your second "for" loop") and it's from the 5th Chapter ("Introduction to 'For' Loops in JS")

The console says "[ undefined ]" and the normal Error message is: "Oops, try again. Make sure you're pushing letters to the hits array!"

var text = "Hey Gijs, are you busy doing things like a Gijs would do? You know, things every Gijs does in the world?";

var myName = "Gijs";

var hits = [];

for (var i = 0; i < text.length; i++); {
    if(text[1] === "G"); 
for (var j = i; j < (myName.length + i); j++); {
    hits.push("Gijs"[j]);
    }
};
console.log(hits);

#2

Hi these line remove the ; at the end

for (var i = 0; i < text.length; i++); <--
    if(text[1] === "G"); <--
for (var j = i; j < (myName.length + i); j++); <--

you could read more about it here


and here

if(text[1] === "G");

you should put text[i] because like that you put if the second letter of your name is equal to the first name of you rname

The here

hits.push("Gijs"[j])

where you put your name you should put text


#3

Thanks! I wouldn't have ever completed that lesson without your help. :slight_smile:


#4

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