Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created June 24, 2016 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/8402f7447eaed25cd2dee21308eb1e0b to your computer and use it in GitHub Desktop.
Save codecademydev/8402f7447eaed25cd2dee21308eb1e0b to your computer and use it in GitHub Desktop.
Codecademy export
/*jshint multistr:true */
var text = "Hello, I'm Igor. Nice to meet you! Hay, do you like puzzles, I do. Well, what you suggest? Below please find links to archived Q&A discussion for the Search Text for Your Name course. Search Text for Your Name Exercise 1.1: What you'll be building Exercise 1.2: Declare your variables Exercise 1.3: Your. 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 ";
var myName = "Igor";
var hits = [];
for (var i = 0; i < text.length; i++) {
if (text[i] === myName[0]) {
for (var j = i; j < (i + myName.length); j++) {
hits.push(text[j]);
}
}
};
if (hits.length === 0) {
console.log("Your name wasn't found!");
}
else {
console.log(hits);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment