What does it mean?


#1

What does this code mean?

/*jshint multistr:true */
var text = "kingram kingram kingram .";
var myName = "Kingram";
var hits =[];
for (var i =0 ; i < text.length;i++) {
   if ( text[i]==="k" ) {
       for(var j = i;j < myName.length + i; j++){
       hits.push(text[j]);
       }
}

sorry my friends i am Iranian and my language is Persian .sorry for asks like this :disappointed_relieved:


#2
  1. A variable called text is declared as a string equal to "kingram kingram kingram ."

  2. A variable called myName is declared as a string equal to "Kingram".

  3. A variable called hits is declared as an empty array.

  4. A for loop starts, in which the counter i (initially set to 0) continues to increase by 1 until it reaches the same value as the length of text.

  5. An if statement is executed - the condition is that the letter in text (which is accessed using the value from i) equals the character "k".

  6. Inside the if statement is another for loop. This time the counter j is set to the value of i, then increments by 1 until its value is the same as the length of myName added to the value of i.

  7. While the for loop is executing, the letter in text (which is accessed using the value from j) is added to the hits array.


#3

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