5. Your Second For Loop CURIOUS ANOMALY


#1


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


Can't seem to figure out where I'm going wrong. I used someone else's code and it works, but when I comment theirs out and submit mine it says it's not pushing the values to the array. However, I just tried to recreate this and now it's just saying syntax error when I use my code (mine is the one with "Alex" as the name).


/*jshint multistr:true */
var text = "Some text.";

var myName = "Alex";

var hits = [];

for (var i = 0; i < text.length; i++) {
    if (text[i]=== A') {
        for(var j = i; j < myName.length + i; j++) {
            hits.push(text[j]);
        }}}

/*var text = "jolly good show this morning Richard\
ridiculous rain Richard we are ravishing";
var myName = "Richard";
var hits = [];

for (var i = 0; i < text.length; i++) {
    if (text[i] === 'R') {
    for(var j = i; j < myName.length + i; j++){
    hits.push(text[j]);
    }}}*/


#2

OK I found my syntax error, it was just the apostrophe before A in the body of my first for loop... still can't figure out why their code works while mine doesn't though.


#3

Ah, figured it out. I didn't realize that you needed to have your name in the text variable -_-


#4

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