Files
freeCodeCamp/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/find-the-length-of-a-string.md
Nicholas Carrigan (he/him) 3da4be21bb chore: seed chinese traditional (#42005)
Seeds the chinese traditional files manually so we can deploy to
staging.
2021-05-05 22:43:49 +05:30

1.4 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
bd7123c9c448eddfaeb5bdef 查找字符串的長度 1 https://scrimba.com/c/cvmqEAd 18182 find-the-length-of-a-string

--description--

你可以通過在字符串變量或字符串後面寫上 .length 來獲得 String 的長度。

console.log("Alan Peter".length);

字符串 10 將會出現在控制檯中。

例如,我們創建了一個變量 var firstName = "Charles",我們就可以通過使用 firstName.length 來獲得 Charles 字符串的長度。

--instructions--

使用 .length 屬性來獲得變量 lastName 的長度,並把它賦值給變量 lastNameLength

--hints--

不能改變 // Setup 部分聲明的變量。

assert(
  code.match(/var lastNameLength = 0;/) &&
    code.match(/var lastName = "Lovelace";/)
);

lastNameLength 應該等於 8。

assert(typeof lastNameLength !== 'undefined' && lastNameLength === 8);

你應該使用 .length 獲取 lastName 的長度,像這樣 lastName.length

assert(code.match(/=\s*lastName\.length/g) && !code.match(/lastName\s*=\s*8/));

--seed--

--seed-contents--

// Setup
var lastNameLength = 0;
var lastName = "Lovelace";

// Only change code below this line

lastNameLength = lastName;

--solutions--

var lastNameLength = 0;
var lastName = "Lovelace";
lastNameLength = lastName.length;