Console won't log my name


#1


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


I have looked the code up and down but can't find where I went wrong. The console just logs "[]" and I'm not getting an error message.


/*jshint multistr:true */
var text = "Lorem ipsum dolor Alessandro sit amet, consectetur adipiscing Alessandro elit.";
var myName = "Alessandro";
var hits = [];
for(var i = 0; i < text.length; i++){
if (text[i] === "A"){
for(var j = i; j < myName.length + i; j++){
hits.push(text[i])
}}}
if(hits.length = 0) {
    console.log("Your name wasn't found!");
} else {
    console.log(hits);
}


#2

try not to use var j=i, instead only j=i

add a semi colon after
hits.push(text[i]);

hope it will fix your problem


#3

Did both of those things, it didn't work :,(


#4

i have same problem.

I completed the exercise, but doesn't log my name... :frowning:

var text = "Hey, how are you doing? My name is John. I am trying to learn how to code, \but this is not going very well. As usual Mr. John Braz starts loosing interest once he finds something else to do.";

var myName = "John";

var hits = [0];

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

#5

First of all, why are you trying to set hits.length as 0? It should be like

hits.length === 0

Also, I'm pretty sure the lesson states "Your name wasn't found!" instead of nameS.
I hope this helps.


#6

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