admin管理员组

文章数量:1287126

I've created a simple if/else statement like so :

var myName = ["Mark"];

if myName.length <= 3;

{

    console.log("It's not true");

}
else 
{

    console.log("Variable consists of" myName.length);
    console.log("I finished my first course".substring(0,26));

}

Unfortunately, the console returns this error : SyntaxError: Unexpected identifier

I've tried to add square brackets to var myName = "Mark"; but it didn't help.

I've created a simple if/else statement like so :

var myName = ["Mark"];

if myName.length <= 3;

{

    console.log("It's not true");

}
else 
{

    console.log("Variable consists of" myName.length);
    console.log("I finished my first course".substring(0,26));

}

Unfortunately, the console returns this error : SyntaxError: Unexpected identifier

I've tried to add square brackets to var myName = "Mark"; but it didn't help.

Share Improve this question edited Nov 16, 2014 at 1:36 user3717023 asked Sep 24, 2013 at 18:58 Danny_StudentDanny_Student 1531 gold badge3 silver badges11 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 5

With

var myName = ["Mark"] 

you are assiging an array to the myName, which is not what you want in this case:

var myName = "Mark"

You have to use parentheses around the if-condition. Also the semicolon is wrong:

if (myName.length <= 3){
     ...
}

In the else-block you've got the first statement wrong. You have to use + to concatenate the arguments that you want to print:

console.log("Variable consists of" + myName.length);

本文标签: