5/7 "Make sure you're pushing letters to hit the array "


#1

The Code:

/*jshint multistr:true */
var text = " Unknown Humans have never ever known the limits of the Unknown. Unknown Unknown Space limits Blah blah blah blahblity.";
var myName = "Unknown";
var hits = [7];
for(i = 0; i < text.length; i++) {
    if(text[i] === 'U') {
        for(U = i;  U< (myName.length + i); U++) {
            hits.push(text[U]);
        }
    }
}

Can you fix it / help me? It keeps on saying Make sure you're pushing letters to hit the array


#2

/*jshint multistr:true */
var text = " Unknown Humans have never ever known the limits of the Unknown. Unknown Unknown Space limits Blah blah blah blahblity.";
var myName = "Unkown";
var hits = [];
for(var i = 0; i < text.length; i++){
   if(text[i] === "U") {
      for(var j = i; j < i + myName.length; j++) {
          hits.push(myName)
      }
   }
}

This is what I would have done if I used your code, now instead of just copy and pasting the code let's find your issue
Now I believe that your issue is that you had already set var hits to a number which should not have been done at the time, also I believe that you already having U as the first letter in your name messed up when you used U in the for statement.
If I am wrong I apologize but this is what I believe is wrong from what you did.


#3

@claradavies Seems to be a good first approach.
@m3softworks Have you tried it after fixing this? What kind of error message do you get?
Also when you use a variable for the first time better use var in front of it (i and U).


#4

i fixed thanks tho :stuck_out_tongue:


#5

/*jshint multistr:true */
var text="rajkumar hello world";
var myName = "rajkumar";
var hits = [];
for(var i=0; i < text.length;i++){
if(text[i] === "r"){
for (var j=i; j<(i+myName.length);j++){
hits.push('r');
}
}
}

This is my code how to complete this as using hits.push inside the starting letter in the array


#6

LOL "Blah blah blah blahblity" - I laughed for about 5 minutes


#7

Why you laugh? Ha? here nothing fun is happen.


#8

"Blah blah blah blahblity" i thought was funny. I have a sense of humour.


#9

Nope, nothing funny could ever happen here /s