5. Your Second For Loop CURIOUS ANOMALY



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++) {

/*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++){


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.


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


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