7 ? Idk how i did this


Well Nothing is wrong but in 7. Victory it says to make it where it only works with your name but I didn't have to change anything and I have Kelly in the text but, it doesn't say my name as many times as it shows up. Did I add code that made it only read for my name and I didn't know it if so I would like to know what I did so I could do it again if I needed to. Ps. if I remove all names except Kelly it works as in it says "Your name wasn't found" so it not it just finding the "K" and saying "Kevin"

/*jshint multistr:true */
var text = "Hi my name is Kelly. I hear alot about you Kevin.Wow \
Kevin is a cool name."

var myName = "Kevin"

var hits = ["Kevin"]

for (var i=0;i < text.length; i ++){
if (text[0] === "K"){
    for (var j = i; i + myName.length;i++){

if (hits.length === 0) {
    console.log("Your name wasn't found!")


Should be an empty array to receive hits.

Should be text[i]. I believe it is in lesson 4 where we swap out our letter for a dynamic expression that can find any first letter, regardless of myName.

if (text[i] === myName[0])

Should only be pushing one letter at a time.

There are a number of ways we can complete this exercise. May I assume you know about substr()? We can use it in place of text[i] in the if statement.

if (text.substr(i, myName.length) === myName) {
    for (var j = i, ...

We're looking ahead to see if all the five letters from the pointer onward match the name exactly, then we're just pushing one letter at a time onto the hits array.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.