Some question through out the course "Search Text for Your Name"


I am a beginner and I come across some questions but I can't find the answers online. I hope you guys experienced here can help me. Thank you so much!
This is my code:

text = "adf Harry sadf Harryasdf Harry Harrydf ff g y a y";
var myName = "Harry";
var hits=[];
for (var i=0; i if (text[i] === "H") {
for ( var j=i; j<(myName.length+i);j++) {
if (hits.length===0) {
console.log("Your name wasn't found!");

I have compared my code with the original "Eric" one, but I still can't figure it out the difference ( which leads to different kinds of results).

  • When I come to loop, the term "+1" is equal to "++" but when I make a change on the first few pages, replace "++" by "+1" and vice versa, the page begins to crash. Could anyone explain this to me ?

for ( var j=i; j<(myName.length+i);j++) {
- at this line, if I set j<=(myName.length+i) , the result printed out on each line, I have no idea why

if (text[i] === "H") {
- So the "i" will run from the begging till the end and only takes "H". why does it also take other letters?


Operators have return values. They are essentially functions.
5 + 1 returns 6, it does not change any of its operands

var a = 5;
console.log(a + 1); // 6
console.log(a);     // 5

++ after a variable name will return the variable's value and then increment it

var a = 5;
console.log(a++); // 5
console.log(a);   // 6

++ before a variable name will first increment and then return the new value

var a = 5;
console.log(++a); // 6
console.log(a);   // 6