Need heeelp


#1


Hello, I'm stuck at this point. What is wrong in my code? someone help me please!



Oops, try again. It looks like your second 'for' loop isn't pushing values to the hits array. Make sure it's working properly and that myName's text appears somewhere in the text variable.


text = "Hello it's me";
var myName = "Veronique";
var hits = [];
for(var i = 0; i < text.length; i++) {
    if (text[i] === "V") {
        
        for(var j = i; j < (myName.length + i); j++) {
			hits.push(text[j]);
		}
    }
}


#2

your text:

text = "Hello it's me";

name is not in it, so your name can't be found, so nothing can be pushed, so an error message is raised


#3

Oh that was simple, thank you so much!!

On the next chapter, the answer seems to be right but the console shows "0", hum, is my code not supposed to print out my first name?

var text = "Hello it's me Veronique";
var myName = "Veronique";
var hits = [];
for(var i = 0; i < text.length; i++) {
if (text[i] === "V") {

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

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


#4

I've made some changes according to other posts. But still get a weird console message, is there something wrong?

var text = "Hello it's me Veronique";
var myName = "Veronique";
var hits = [];
for(var 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 name wasn't found")
} else {
console.log(hits)
}


#5

to check if something is equal, two equal signs should be used, a single equal sign means assign, and you want to check if zero equals hits.length


#6

Yes I've tried that! (above is my updated code)


#7

then it should be working?


#8

oh that must be how the site works but i get a very weird message in the console window, is it not supposed to print out only my name ?


#9

this line:

if (text[i] === myName[0]);

the semi-colon prevents the if clause from working properly, remove the semi-colon


#10

Ah great, it works fine now, thanks a lot!!


#11

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