Visitar URL original
javascript/problems/string-length/problem_zh-tw.md at master · hackademymx/javascript · GitHub
Skip to content

Latest commit

 

History

History
29 lines (16 loc) · 783 Bytes

problem_zh-tw.md

File metadata and controls

29 lines (16 loc) · 783 Bytes

在程式中我們經常需要知道一個字串中到底包含了多少字元。

你可以使用 .length 來得到它。下面是一個例子:

const example = 'example string'
example.length

注

不要忘記 example 和 length 之間的點(英文句號)。

上面這段程式碼將返回一個 number,也就是數字,指明字串中的字元個數。

挑戰:

建立一個名為 string-length.js 的檔案。

在該檔案中,建立一個名為 example 的變數。

將字串 'example string' 賦給變數 example。

使用 console.log 印出這個字串的length,也就是長度到終端機上。

執行下面的命令來檢查你寫的程式是否正確:

javascripting verify string-length.js