语法错误:意外令牌
问题描述:
菜鸟编码器在这里!语法错误:意外令牌
我正在学习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));
答
有两个问题与你的例子:
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));
+0
非常感谢您指出。我现在可以继续教程了!很重要的一点是你会花时间帮助别人学习,我希望有一天能学到足够的知识并以同样的方式帮助别人。 – 2015-04-01 17:43:44
答
这是正确的答案
var myCountry = "myCountry";
console.log("myCountry".length);
var myCountry = "myCountry";
console.log("myCountry".substring(0,3));
这是什么语言? – 2015-03-31 16:49:34