Sivery
Sivery

Reputation: 60

JS function doesn't works

I'm programming at the moment a very simple Log-In. I want to make a function, that checks if char is the same as "V7Z'13Px8DtyJp0n'JD;". So far I've done this:

function check(char) {

    If(char == "V7Z'13Px8DtyJp0n'JD;") {

        alert("right");

    }

}

But my Editor(Visual Studio Code) and my Browser(Google Chrome) thinks the last } is wrong. Please Help Me.

P.S. Sorry for my Englisch ._.

Upvotes: 0

Views: 72

Answers (4)

Olta Al
Olta Al

Reputation: 26

you just need to replace If with if

function check(char) {

    if(char == "V7Z'13Px8DtyJp0n'JD;") {

        alert("right");

    }
}

:)

Upvotes: 1

Amiga500
Amiga500

Reputation: 6131

As other users pointed out, you have a syntax error with the if statement.

It should look like this:

function check(char) {
    if(char === "V7Z'13Px8DtyJp0n'JD;") { // Code changed here
        alert("right");
    }
}

Having said that, that syntax error is least of your problems. Any IDE nowadays should give you a warning about the simple syntax error. Simply search for JavaScript editor and use one. It will help you a lot.

Another thing worth mentioning here is the comparison operator inside your if statement. Long story short, you should always try to use triple equals '===' rather than '=='. You can read more about it here. Also, for easier understanding, you can read it here (same topic)

Upvotes: 1

Sanderr
Sanderr

Reputation: 149

I see that your if statement uses a capital 'I'. If you use if it should do the job.

function check(char) {

    if(char == "V7Z'13Px8DtyJp0n'JD;") {

        alert("right");

    }   
}

Upvotes: 1

Paul Bönisch
Paul Bönisch

Reputation: 294

You have a typo on "If" -> "if":

function check(char) {

  if(char == "V7Z'13Px8DtyJp0n'JD;") {

    alert("right");

  }
}

Upvotes: 0

Related Questions