Can anyone could help me? Really easy one


#1


var text = "On and off Joshua keeps continuing going to Court";
var myName = "Maria";
var hits = [];

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

{
    if (hits < 1); {
    console.log("Your name wasn't found!");
}
else (hits => 1); {
    console.log("Judge Edward George Armstrong is still alive. Doesn't he?");
}
};
-------------------------------------------------------------------------------------------------------
Eventually, I got a syntax error. I think this is simple, but I'm also lazy tho:(
Can anyone who are looking for help, can you get me a link to if/else statement? Then I'll take out and care
of your error code, too.  Thanks anyway! (I major in CSS/Command links.)

Thank you so much for your attention, originally I was going to Solutionize the first one, but I also think Answer 2 looks quite legit to me. But don't be depressed, Packy!! (THANK YOU!!!!)


#2

Remove this part of your code 1) Incorrect use of brackets 2) Not required for the lesson you are on.

{
    if (hits < 1); {
    console.log("Your name wasn't found!");
}
else (hits => 1); {
    console.log("Judge Edward George Armstrong is still alive. Doesn't he?");
}
};

#3

You need to check your for loops(both of them)
for (i = 0; i < text.length + 1; i++) adding 1?
and
for (var j = i; j < i + myName.length; j++)

also in second part, You're providing ; after if/else
if (hits < 1); why put ; ?

also else goes without condition ----- (1)
else (hits => 1); ? erase ; and follow 1

also..
Make sure that opening curly brackets { are in same numbers as closing curly brackets }.

if/else syntax

if (condition) {
   //your code
}
else {
    //your code
}

#4

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