Your "if" Statement


#1



I keep getting syntax errors. I am working on the exercise mentioned above. Any help would be appreciated.


Replace this line with your code. 
<img src="//codecademy-discourse.s3.amazonaws.com/original/5X/4/8/2/3/48236fa3d5a61daab5d7c8840e9ee548aff3763a.png" width="590" height="246">

#2

This code doesnt match with your link?!


#3

Sorry about the issue and thanks for the feedback. I tried to take a screen shot - did not work to say the least. Here is a copy of my code so far and I am stuck.

var text = "Hey, my name is Warren. My middle name is Jay.";
var myName = "Warren";
var hits = [];
for (var i=0; i< myName.length[i]; i++) {
if (text[i]=== 'W') }

Keep getting syntax errors.

Thanks.


#4

The hidden screenshot :wink::


#5

Your problem is here:

if (text[i]=== 'W') }
                    ^

You didn't finish all of the code, so it would raise an error for that, but the syntax error is because this brace is the wrong way around.

Do it like this:

/*jshint multistr:true */
var text = "Hey, my name is Warren. My middle name is Jay.";
var myName = "Warren";
var hits = [];
for (i = 0; i < text.length; i++){
    if (text[i] === "W") {
        
    }
}

#6

Thanks for the and getting the screenshot to work. I will try this and let you know - your help is appreciated.


#7

Happy to help :)


#8

That DID work! Thanks again.


#9

No problem :slight_smile:


#10

Btw: When you were supposed to declare the variables (https://www.codecademy.com/en/courses/javascript-beginner-en-XEDZA/0/2?curriculum_id=506324b3a7dffd00020bf661) you should have put your name 3 times in there^^


#11

Nope! It says:

Declare and set the following three variables: 01. text, and make it a string containing some text. Place your name in there a couple of times!

It does not say how many times specifically:

And it wouldn't affect the way the code works either, so as long as there is at least one instance of your name, the code will work and the exercise will pass :slight_smile:


#12

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