6/7 Help?


#1

What am I doing wrong?

/*jshint multistr:true */
var text = "Hey, what is your name? My name is Miriam, but some people call me Mir. I love food and music and all of that amazing stuff.";
var myName = "Miriam";
var hits = [];
for (i = 0; i < text.length; i++) {
if (text[i] === "M")
{ for (var l = i; 1 < (i + myName.length); 1++) {
hits.push(text[l])
}
}
}
console.log(hits[0]);
if (hits === 0) {
console.log("Your name wasn't found!");
}
else
{
console.log(hits);
}


#2

Hi @futuresta! There is a simple fix in your javascript code!

Your code:

Correct Code:

 for (var i = 0; i &lt; text.length; i++)

Hope this Helped! If it didnt please Reply! Cheers!


#3

It didn't work. What is the &lt supposed to do? Also, should I get rid of the var hits = [] on the line before?
Thank you


#4

@futuresta please watch for the { } and make sure to open and close them properly. Also in your second for loop, you need to end the "hits.push(text[l])" with ';' at the end.

Also, the question states,

If you don't have any hits, log "Your name wasn't found!" to the console.

Think about the first part carefully. var hits is an array that contains a string of letters found from your loop. When each letter is found, it records to the 'hits' array. In other words, if it has any matching letter, the length of this array won't be zero. Convert this idea and put it into the codes.

so I've tried the if condition at the bottom as:

if (hits.length === 0) then { //Message }
else
{ console.log(hits);}


#5

var text = "Hey, what is your name? My name is Miriam, but some people call me Mir. I love food and music and all of that amazing stuff.";
var myName = "Miriam";
var hits = [];
for (i = 0; i < text.length; i++) {
if (text[i] === "M")
for (var l = i; l < (i + myName.length); l++) {
hits.push(text[l])
}
}
//console.log(hits[0]);
if (hits === 0) {
console.log("Your name wasn't found!");
}
else
{
console.log(hits);
}

After submit : [ 'M', 'y', ' ', 'n', 'a', 'm', 'M', 'i', 'r', 'i', 'a', 'm', 'M', 'i', 'r', '.', ' ', 'I' ]


#6

if(hits < 0)
console.log("Your name wasn't found!");
else
console.log(hits);

this works for me! hope that i can help yoo