6/7 Issue with logging


#1

var text = "Hey Lucas! Coding is supposed \
to be fun Lucas.";
var myName="Lucas";
var hits=["L"]
for ( var i=0; i > text.length; i++) {
if(text[0] === "L") {
for (var j=i; j > (i + myName.length); j++) {
hits.push("L");
}
if(hits.length=0) {
console.log("Your name wasn't found!");
}
else {
console.log(hits);

}
}

};

All i am getting is an error saying that i didn't log my hits? Whats going on?


#2

Thats because you only push L to your hits array.
you should push the hole name and that dynamic.

Use text[]


#3

Not quite sure what you mean, can you give me an example? Also, if that was the issue, how was I allowed to pass the previous exercise with the code that I had? Thanks for all of your help


#4

var text = "Hey Lucas! Coding is supposed \
to be fun Lucas.";
var myName="Lucas";
var hits=[]
for ( var i=0; i > text.length; i++) {
if(text[0] === "L") {
for (var j=i; j > (i + myName.length); j++) {
hits.push("Lucas");
hits[0];
}
if(hits.length=0) {
console.log("Your name wasn't found!");
}
else {
console.log(hits);

}

}
};

tried this and variations and getting same error warning


#5

var text = "Hey Lucas! Coding is supposed \
to be fun Lucas.";
var myName="Lucas";
var hits=[]
for ( var i=0; i < text.length; i++) {
if(text[0] === "L") {
for (var j=i; j < (i + myName.length); j++) {
hits.push(text[j]);
hits[0];

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

}

}
};

I'm here now, nothing doing. Super confused


#6

Your code is not complete good.

for (var j=i; j > (i + myName.length); j++) {
hits.push("Lucas"); // this is wrong or why did you loop? here you should work with text[]
hits[0]; // remove that it is not necassary
}

if(hits.length=0) { // you didnt compare. (==/=== for compare and = for declare
console.log("Your name wasn't found!");
}

#7

I have also tried the code with the removed hits[0]; and it still doesn't work. I guess i'm struggling with the why of all of this. I get up to a point the code, however, without in context or explanation i'm struggling with understanding what do to where. I feel like i'm just replacing words in a sentence instead of speaking the language. Any suggestions for sights other than CA for learning this? Not wholly satisfied with CA at this point.


#8

I will give you here the correct code and than lets talk via private message.

var text = "Hey, how are you \
doing? My name is Emily.";
var myName = "Emily";
var hits = [];

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

#9

I did this but the "Did you remember to log the result of your search to the console?" error still persist. Please help


#10

Show me please your complete Code :slight_smile: Thx


#11

It's okay now. Just log out and exit browser then log back in. Then using the code above, just run it.:slight_smile:

To quote the famous IT Crowd saying, "Have you tried turning it off and on again?"