6. Log it! Search text for your name


#1

This is my code. When I enter it I pass the test, but the computer logs [ undefined ]

Cant get my mind on what I am doing wrong here? Any help is more then welcome.

Kind regards


#2

@robertkooyman,
Please display the full code you are using.


#3

Just edited my post. I clicked enter way too quick :slight_smile:


#4

@robertkooyman,
The structure should look like

for ( init; condition; final-expression ) {
   if ( condition ) {
      //IF code-block
      for ( init; condition; final-expression) {
         hits.push( text[j] );
      }
   }
 }

===============================================

The curly-brackets-{ } are used
to encapsulate code-which-should stand together
into code-blocks


#5

Thanks for the great support! Works a bit better I guess now :slight_smile: However still one problem; computer says: "Your name wasn't found!":blush:


#6

@robertkooyman,
-1
For Javascript a semi-colon-; is an End-of-Statement indicator.
Looking at your code
In your 2nd FOR-loop setup, you are using this semi-colon-; BEFORE its code-block....
thus for the Interpreter your code would look like

for ( init; condition; final-expression ) {
   if ( condition ) {
      //IF code-block
      for ( init; condition; final-expression);
      //Following code will be executed AFTER the 2nd FOR- has ended. 
      hits.push( text[j] );
   }
 }

-2
In your 2nd IF condition
you should be checking
the length of the =hits= Array.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array


#7

Thanks again. I almost do not dare to say this, but I still have one question; what do you mean with the last part of your answer? My code returns the complete text now? :blush:


#8

@robertkooyman,
You completed the section perfectly.... :lock:


#9

Huh, but I do not get it? I thought it should have logged only the name "Robert" now? Instead I get the entire text back written like this:


#10

@robertkooyman
Display the full code you are using now,
it is different to your Post
seeing the returned values in hits
it is a totaly different text