5. IDK WHATS WRONG. Can somone fix my mistakes AND give me the full code


#1

https://www.codecademy.com/courses/javascript-beginner-en-XEDZA/0/5?curriculum_id=506324b3a7dffd00020bf661#

There was a problem with you syntax

var text ="My name is Saihaan and that name belongs to Saihaan.";
var myName= "Saihaan";
var hits = []
for (var i = 0; i < text.length; i++)
{
    if (text[i] === "S")
    {
        for(j = i; j = myName[0].length; j++)
        {
            hits.push(text)
    }
}

#2

Can someone fix my mistakes AND give me the full code

Nope.


The first problem is the fact that the outer for loop is not closed (missing }).


The second problem is in condition of the inner for loop:

j = myName[0].length

We usually use some comparsions here (like j > 12, j === 3 or something like this) and you decided to assign new value to j. Why?


Are you sure that you want to push whole text to the hits array?

hits.push(text)

Or maybe only the actual letter? text[j]


#3

omg ty your the best
and dont u mean the inner for loop isnt closed


#4

Thank you for your kind words :slight_smile: You're very welcome.

and dont u mean the inner for loop isnt closed

It does not really matter, the effect is exactly the same - you need to add one } somewhere in the last lines of your script :slight_smile:


#5

ty
and i had to do

var text ="My name is Saihaan and that name belongs to Saihaan.";
var myName= "Saihaan";
var hits = []
for (var i = 0; i < text.length; i++)
{
if (text[i] === "S")
{
for(j = i; j < i + myName.length; j++)
{
hits.push(text[j])
}
}
}

j > myName crashes my browser


#6

Ty here and on my other post


#7

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