2015-03-31 98 views
-1

菜鳥編碼器在這裏!語法錯誤:意外令牌

我正在學習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

這是什麼語言? – 2015-03-31 16:49:34

回答

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)); 
+0

非常感謝您指出。我現在可以繼續教程了!很重要的一點是你會花時間幫助別人學習,我希望有一天能學到足夠的知識並以同樣的方式幫助別人。 – 2015-04-01 17:43:44

0

這是正確的答案

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


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