Victory! User typed answer to search for


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-XEDZA/0/7?curriculum_id=506324b3a7dffd00020bf661


There is no error message. My problem is that when i type in the name in the prompt the name isnt applied.
I tried making it so that all names could be typed in (even though not all names can be found). I tried applying some stuff from the rock paper scissors lessons but i just couldnt get it to work. What am i doing wrong? Thank you for your help


var text = "wieqjoe  qweijoqwjeioq wjqeowqijeoq Jqwklsaldnlaåe qwoepkqkeælk\
welæqemæq Jack wkelmqlwknelqwknl wei+0wqeæakælda Jack kqwlemlqknl";
var myName = prompt("What is your name?");
var hits = [];

var theirName = function(myAnswer) {
    for (var i = 0; i < text.length; i++) {
        if (text[i]  === myAnswer.substring[0]) {
            for(var j = i; j < (myAnswer.length + i); j++){
                    hits.push(text[j]);
            }
        }
    }
};

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

theirName(myName);


#2

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

Hint**
this is outside of your function ?


#3

I've tried putting those two inside the function but it still doesnt help...


#4

Did you put them just before ending } (of function) ?
(I actually tested this code and It worked fine)

Another way..
Get rid of this function system and try to test for one case!


#5

I doubt this would help but maybe try placing var myName after you log your hits; right above "theirName(myName);". Also add console.log(theirName(myName); so that it is print in the console. I'm new but trying to learn by debugging so I appreciated any feedback! Hope you figure it out!


#6

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