Created
November 9, 2015 07:13
-
-
Save marlibs3-zz/e6877fd85b3397715c26 to your computer and use it in GitHub Desktop.
Find my Name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jshint multistr:true */ | |
var text = "One day Marta went to the shops and ate an entire chicken.\ | |
She was so full that the chicken wings came out of her back and Marta became a hybrid chicken human. As she went rabid and started pecking people Andrew started crying and shouting 'Marta! No!'. It was all very sad because they all died." | |
var myName = "Marta" | |
var hits = [] | |
for (var i = 0; i < text.length; i++) | |
{ | |
if (text[i] === 'M') | |
{ | |
for (var j = i; j < i + myName.length; j++) | |
{ | |
hits.push(text[j]); | |
} | |
} | |
} | |
if (hits === 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