Log it


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-XEDZA/0/6?curriculum_id=506324b3a7dffd00020bf661

My code run perfectly , but there is bug in this code. This code print all the letters after "s"


/*jshint multistr:true */
var text = "ssfgd sonu dasd sad sd sasd\
           saasff adasd sonu asssfa sd\
           asdasd sonu sadsd.";
var myName = "sonu";
var hits = [];

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

output :- [ 's',
  's',
  'f',
  'g',
  's',
  'f',
  'g',
  'd',
  's',
  'o',
  'n',
  'u',
  's',
  'd',
  ' ',
  's',
  's',
  'a',
  'd',
  ' ',
  's',
  'd',
  ' ',
  's',
  's',
  'a',
  's',
  'd',
  's',
  'd',
  ' ',
  ' ',
  's',
  'a',
  'a',
  's',
  's',
  'f',
  'f',
  ' ',
  's',
  'd',
  ' ',
  's',
  's',
  'o',
  'n',
  'u',
  's',
  's',
  's',
  'f',
  's',
  's',
  'f',
  'a',
  's',
  'f',
  'a',
  ' ',
  's',
  'd',
  ' ',
  ' ',
  's',
  'd',
  'a',
  's',
  's',
  'd',
  ' ',
  's',
  's',
  'o',
  'n',
  'u',
  's',
  'a',
  'd',
  's',
  's',
  'd',
  '.',
  undefined


#2

ohh sry
this was also explained in next lesson


#3

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