QUOTE
/*jshint multistr:true */
text = "Blah blah blah blah blah blah Eric \
blah blah blah Eric blah blah Eric blah blah \
blah blah blah blah blah Eric";
var myName = "Eric";
var hits = [];
// Look for "E" in the text
for(var i = 0; i < text.length; i++) {
if (text[i] === "E") {
// 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);
}
text = "Blah blah blah blah blah blah Eric \
blah blah blah Eric blah blah Eric blah blah \
blah blah blah blah blah Eric";
var myName = "Eric";
var hits = [];
// Look for "E" in the text
for(var i = 0; i < text.length; i++) {
if (text[i] === "E") {
// 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);
}
^ THIS IS THE (SHOULD BE) END PRODUCT
QUOTE
/*jshint multistr:true */
var text = "Kok says hello. Kok says hi. Hello Kok Have a nice day."
var myName = "Kok"
var hits = []
for(var i = 0; i < text.length; i++){
if (text[0]==="K"){
}
}
var text = "Kok says hello. Kok says hi. Hello Kok Have a nice day."
var myName = "Kok"
var hits = []
for(var i = 0; i < text.length; i++){
if (text[0]==="K"){
}
}
^THIS IS MY CODE
I am learning Javascript and stuck with this for thing... It's supposed to look in a text for my name.
I don't understand the "for" command and how to push data into an array...
Can a code master here take some time... to explain briefly how this code supposed to function?
Thank you for reading this and have a nice day!