Is the code correct?


#1


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


Im not sure how de code has to look when finished. Thats what my console.log is showing .
Your name wasn't found!
Your name wasn't found!
Your name wasn't found!
Your name wasn't found!
Your name wasn't found!
Your name wasn't found!
Your name wasn't found!
Your name wasn't found!
Your name wasn't found!
Your name wasn't found!
Your name wasn't found!
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?',
'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?',
'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?',
'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?',
'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?',
'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?',
'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?',
'My Name is Philipp. Is your name also Philipp?' ]
[ 'My Name is Philipp. Is your name also Philipp?',
'My Name is Philipp. Is your name also Philipp?' ]


heres my code...pls help. ty

var text = "My Name is Philipp. Is your name also Philipp?"
var myName = "Philipp"
var hits= []

for(i=0; i < text.length; i++){
 
    if(text[i] === myName[0]){
        for(j=i; j < i + myName.length; j++){
    }
    hits.push(text)
}
if(hits.length === 0){
    console.log("Your name wasn't found!")
}  else{ 
console.log(hits)
}
}


#2

There's a few reasons why it's not working. First of all hits.push should be in your for statement. Second you have an extra } at the bottom. Third, you are missing your } from your for statement. Fourth, not sure if the exercise wanted it, but I'm not using var for my hits array. The code should look more like:

var text = "String Chris String Chris Chris String"
var myName = "Chris"
hits = []

for (var i = 0; i < text.length; i++){
    if (text[i] === "C"){
        for (var j = i; j < (i + myName.length); j++){
            hits.push(text[j]);
        }
    }
}

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

#3

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