I need help, please :(


#1

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

I keep getting an error message that I need to make sure I am pushing it to the array. I can’t find the error in my code causing it to act like this

```
/*jshint multistr:true */
var text = "I would like to know if Karen runs races. The races are fast and frequent but it would be nice to try. Personally I think Karen would like to play basketball instead. She has the height for it and she has very good aim. Maybe she should play basketball. Instead Karen does not do much. She is very content staying inside and reading books and that is okay.";

var myName = "Karen";

var hits = [];

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

#2

What do you see that could be a syntax problem in this line of code? Hint: There are 2 problems.

  • Look at the var declaration.
  • Look at the semi-colon after the conditional expression.
if(text[i] === 'K');{

Same syntax problem. );{ should be => ) {.

for(var j = i; j < (myName.length + i); j ++);{

Same syntax problem. );{ should be => ) {.

Tip:

The semi-colon says to JavaScript “Hey, this is the end of the instruction.” For code blocks, you don’t need a semi-colon. Why? You are defining the code block with the curly braces.

for (var i = 0; i < text.length; i++) {
   // your code here
}
if (text[i] === 'K') {
   // your code here
}

Notice, there’s no semi-colon after the conditional expression.


#3

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