1.4 KiB
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
將會出現在控制檯中。
例如,如果我們創建了一個變量 const firstName = "Ada"
,我們可以通過使用 firstName.length
找出字符串 Ada
的長度屬性。
--instructions--
使用 .length
屬性來獲得變量 lastName
的長度,並把它賦值給變量 lastNameLength
。
--hints--
不能改變 // Setup
部分聲明的變量。
assert(
code.match(/let lastNameLength = 0;/) &&
code.match(/const 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
let lastNameLength = 0;
const lastName = "Lovelace";
// Only change code below this line
lastNameLength = lastName;
--solutions--
let lastNameLength = 0;
const lastName = "Lovelace";
lastNameLength = lastName.length;