.push() DOES NOT WANT TO COOPERATE


#1




/*jshint multistr:true */

var text = "My name is Zobee. Just incase you forgot, \
my name is Zobee.";

var myName = "Zobee"

var hits = [];


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


#2

Stray closing brace in that line.

The title of this topic is misleading, though. There is no push() statement in this code. How is it not cooperating?


#3

Where do you see a stray closing brace?

for open
 if open
   for open close
 if close
for close

#4

My mistake. Braces are fine. Title is still misleading, unless it meant to read... "Somebody give the code..." We see so much copied code which the user asking the question could not possibly have written, judging by the question they ask. Do we call this out? Or do we pander to it? Or just give it a pass and ignore?


#5

I can assure you I wrote this code. I just cant seem to find where to insert or use the 'push' command... Help would be nice instead of assuming.


#6

My apologies. I should have just mentioned that there is an example right in the lesson text.


#7

I realize, but regardless, I was not able to input the command.This is not any copied code for the record. Its all mine. Feel free to quiz if needed.


#8

Are you saying the you could not type the code into the editor?


#9

Currently speaking with an advisor on it. Just cant figure out how/where to put/use the '.push' method.


#10

/*jshint multistr:true */

var text = "My name is Zobee. Just incase you forgot, \
my name is Zobee.";

var myName = "Zobee"

var hits = [];

for (var i = 0; i < text.length; i++){
if (text[i] === 'Z') {
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);
}

// End of code

  • Figured it out!

#11

Glad for that, even though you didn't, really. It contains at least one error.


#12

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