This forum is now read-only. Please use our new forums! Go to forums
Please help me! I cant figure this out! myName.length
I am doing what the instructions say, but it wont pass me. What am I doing wrong? Some explanation would be appreciated. Below is my code.
/*jshint multistr:true
var text = "Hey! my name is Sharon! I love music \ and am awesome!";
var myName = "Sharon";
var hits = [];
for(var I = 0; I <text.length; I++){
if(text[j]==="S"){
for(var j = I; j <myName.length; j++){
}
}
}
Thank you for the help!
Answer 55bf974393767660f0000002
/*jshint multistr:true */
var text = “Hay! my name is Sharon! I love art. I also
love music!”;
var myName = “Sharon”;
var hits = [];
for(var i = 0;i < text.length; i++){ if(text[i]===”S”){
}
for(var j = i; j < i; j ++){
hits.push(j)
}
}
I hope this helps. I seriously can’t figure this out.
Answer 55bacf4f937676797100006f
Hi Sharon,
I think you need to be pushing text[j]
to the hits
array in your second for
loop.
7 comments
Thanks, I’m a little confused though. Would you mind explaining it a bit so I know what I did wrong?
Um… you forgot to do anything in the second for
loop…
Oh wait, did you want to know what pushing text[j]
to the hits
array did?
It just adds the j
th character in text
to hits
. So, if text contains one word, “hello”, and j
equals 3, then in hits
we would see "l"
. Does that help?
I don’t know. I put ‘j’ in the ‘hits’ array, but I keep getting this
Oops, try again. Careful: your second ‘for’ loop should stop when it reaches its current point in the string + myName.length
Could you please post your entire code? (Please in a reply, not a comment)
Yah no problem.
Answer 55bc9ff2e39efefadb000082
/*jshint multistr:true */
text = "Lelouch Vi Britannia commands you! shineii!! Watashiwa Zero!!moshi moshi!! Watashiwa Zero!! Watashiwa Zero!! Watashiwa Zero!!";
var myName = "Zero";
var hits = [];
// Look for "Z" in the text
for(var i = 0; i < text.length; i++) {
if (text[i] === "Z") {
// If we find it, add characters up to
// the length of my name to the array
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);
}
var game = function() {
var qoutes = prompt("Before you proceed. Do you want to read a famous qoutes of mine?");
switch(qoutes) {
case "yes":
alert("If the King doesn't move, how suppose will his ordinates follow");
break;
case "no":
alert("You will regret it!! Lelouch Vi Britannia commands you, Shineii!!")
break;
default:
alert("Die!!!!!!")
}
};
game();
8 comments
what?
I just play a little bit xD
lol, can you help me though, please
haha, ok. can you state what is your problem? I suggest Zeke Y has a better one
Oh, I see. Here:) in your for loop copy and paste this
for(var I = 0; I < text.length; I++) { if (text[I] === “S”) { for(var j = I; j < (myName.length + I); I++) { hits.push(text[j]); } } }
just let me know if it still doesnt work:D
Thank you soooooooooooooo much! And FYI, the I++ is supposed to be a j++. Thank you!!!!!!!!!!!!XD
oh xD, my bad.. hehe
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
3 comments
You’re closing your
if
statement before the second for loop. The for loop needs to be inside the if statement. Then, change this line:hits.push(j)
to this:hits.push(text[j]);
Thanks, I figured it out with a little help from Lelouch Lamperouge. Thanks foe the help though!
No problem, glad Lelouch was able to help you get it sorted out :)