i done the same but not fixed
var text= “Hey Soni how are you?
What are doing Soni?”;
var myName = “Soni”;
var hits = ;
for(var i = 0; i <text.length; i++); {
if ( text[i] === "S") {
for(j = i; j<( myName.length +i); j++) {
hits.push(text[j]);
}
}
};
1 Like
i figured out , thank you
But you stIll missing the first for loop
for(var i = 0; i
I have fixed all, thank you
1 Like
Hello, I keep getting an error message stating that the second for loop isn’t pushing variables to the hits array.
/*jshint multistr:true */
var text = “Hello Luke.”
var myName = “Luke”;
var hits = ;
for (var i = 0; i < text.length; i++){
if (text[i] === "L"){
for (var j = i; j < (myName.length + i); j++)
{
hits.push([L]);
}
}
}
I was wondering if someone could help me please.
1 Like
hits.push(text[L]); make this instead of hits.push([L]);
and a semicolon ; after last }
Hey, i was also having trouble with this code. This is my code
/*jshint multistr:true */
var text = " Hello my name is Anne";
var myName = "Anne";
var hits = [];
for(var i = 0; i < text.length ; i++){
if(text[i]==="A") {
console.log(myName);
var (j = i; j <= i + myName.length; j++)
{
hits.push(text[j]);
}
}
};
SyntaxError: Unexpected token
That’s my error
1 Like
Hi this part
var (j = i; j <= i + myName.length; j++)
you put var
instead of for
That was it, thanks so much!
1 Like
Totally confused as to what’s wrong with my code:
/*jshint multistr:true */
var text = “When in doubt, ask Tom.”;
var myName = “Tom”;
var hits = ;
for (var i = 0; i<text.length; i=i+1){
if (text[i] === “T”)
{
for (var j=i; j<(text.length+myName.length); j++);
}
hits.push([j])
};
“Oops, try again. Make sure you’re pushing letters to the hits array!” it keeps pushing a number rather than a string and i can’t figure out where the issue is.
1 Like
He did explain it after every line if you will open your eyes.
1 Like
Hello. I know it’ll thousand qwestion but can u explain me pls:
var text = “is Andrey”;
var myName = “Andrey”;
var hits = ;
for (var i = 0; i < text.length; i++){
if (text[i] === myName[0]){
console.log(i); // i = 3
console.log(myName[0]); // myName = “A” is true
for (var j = 0; j < (myName.length + i);j++){ //now we are going the secont iteration and i can’t understand
hits.push(myName[j]); // why we should put myName.length + i Why? We need to count only
// letters of myName but not full the text.
}
console.log(hits);
}
}
It’s work but i still can’t understand this exisice. Thank you for you explanation.
1 Like
I understand what the code is doing, but I cannot seem to get the code to go through correctly no matter what I do/change. Please help. I’m sure it’s something minor and stupid.
var text = “One Lolo Two Lolo Three Lolo Four Lolo”;
var myName = “Lolo”;
var hits = ;
for (var i = 0; i < text.length; i++); {
if (text[i] === ‘L’); {
for (var j = i; j < (i + myName.length); j++); {
hits.push(text[j]);
}
}
}
1 Like
Hi this parts remove the ;
for (var i = 0; i < text.length; i++); <== this
if (text[i] === 'L'); <== this
for (var j = i; j < (i + myName.length); j++); <== this one too
Just as I thought, something minor -_-
But THANK YOU it worked lol
1 Like
What is the problem mate?
1 Like
HI try to add a ;
at the end of all your variables.