语法错误:意外的令牌

时间:2015-03-31 16:37:35

标签: javascript syntax-error token

新手编码器在这里!

我在codeacademy.org上学习并继续收到此错误,即使我确信它已被正确写入。帮助

// Declare a variable on line 3 called
// myCountry and give it a string value.
var myCountry = "Panama";
// Use console.log to print out the length of the variable myCountry.
console.log(.length myCountry);

// Use console.log to print out the first three letters of myCountry.
console.log(myCountry .subscript(0,3));

2 个答案:

答案 0 :(得分:1)

您的示例有两个问题:

console.log(.length myCountry)

不是有效的Javascript;你需要

console.log(myCountry.length)

length是变量myCountry)的属性。

此外,subscript不是JS函数,您需要substring

完整示例:

// Declare a variable on line 3 called
// myCountry and give it a string value.
var myCountry = "Panama";
// Use console.log to print out the length of the variable myCountry.
console.log(myCountry.length);

// Use console.log to print out the first three letters of myCountry.
console.log(myCountry.substring(0, 3));

答案 1 :(得分:0)

这是正确答案

var myCountry = "myCountry";
console.log("myCountry".length);


var myCountry = "myCountry";
console.log("myCountry".substring(0,3) );