Skip to content

Instantly share code, notes, and snippets.

@willianrschuck
Created March 20, 2016 01:50
Show Gist options
  • Select an option

  • Save willianrschuck/75b7a2dc7f4e46206ba9 to your computer and use it in GitHub Desktop.

Select an option

Save willianrschuck/75b7a2dc7f4e46206ba9 to your computer and use it in GitHub Desktop.
// Exercise of the course "JavaScript - Codecademy (https://www.codecademy.com)"
// Student - Willian Schuck
// Creates the variables
var text = "Willian, are now programming. Please, talk with Wilbor";
var myName = "Willian";
var hits = [];
// Exercise requirements.. I will not comment them.. ;P
for (var c = 0; c < text.length; c++) {
if (text[c] === myName[0]) {
// Reset the previus value.. or defines the variable;
var fName = ""
for (var d = c; d < c + myName.length; d++) {
var fName = fName + text[d];
if (fName === myName) {
hits.push(fName);
};
};
// Returns to line 10, if the sentence returns true, it reloads the code of lines 13 - 20;
};
};
if (hits.length == 0){
console.log("Seu nome nao foi encontrado!");
}else{
console.log(hits);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment