我在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));
答案 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) );