You second for loop help!


#1


i couldn't understand this course so i couldn't pass it please help!


var text = "bla bla bla bla bla bla bla bla \ Muhamed bla bla bla bla bla bla bla bla bla \ Muhamed  bla bla bla bla bla bla bla bla"

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


#2

You need to make these changes if(text[i]==="M")
This is because your pretty much asking if one chracter in the whole text is === to the letter M. What you did wrong was that your asking if 1 letter in the text is === Muhamed. Which Is ALWAYS false. Since one letter cannot EVER equal to Mohamed.

Also dont hits.push("hello"), hits.push(text[j]) This will send your prefered letter to an array--which is what the task asks. Dont push hello to the array, Because you wont get right results.

Also Have a good day! :wink:


#3

your if statement should be something like this
if(text[i] === myName[0] )
because you don't want full name you only want the first letter


#4

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