2021-06-15 00:49:18 -07:00
---
id: bd7123c9c448eddfaeb5bdef
2021-07-21 20:53:20 +05:30
title: Encontrar o tamanho de uma string
2021-06-15 00:49:18 -07:00
challengeType: 1
videoUrl: 'https://scrimba.com/c/cvmqEAd'
forumTopicId: 18182
dashedName: find-the-length-of-a-string
---
# --description--
2021-07-09 21:23:54 -07:00
Você pode encontrar o tamanho de um valor de `String` ao escrever `.length` após a variável de string ou literal de string.
2021-06-15 00:49:18 -07:00
```js
console.log("Alan Peter".length);
```
2022-04-13 20:12:58 +05:30
O valor `10` seria exibido no console. Observe que o caractere de espaço entre "Alan" e "Peter" também é contado.
2021-06-15 00:49:18 -07:00
2021-11-03 08:22:32 -07:00
Por exemplo, se nós criássemos uma variável `const firstName = "Ada"` , poderíamos descobrir qual o tamanho da string `Ada` usando a propriedade `firstName.length` .
2021-06-15 00:49:18 -07:00
# --instructions--
2021-07-09 21:23:54 -07:00
Use a propriedade `.length` para contar o número de caracteres na variável `lastName` e atribui-la a `lastNameLength` .
2021-06-15 00:49:18 -07:00
# --hints--
2021-07-26 23:39:21 +09:00
Você não deve alterar as declarações de variáveis na seção `// Setup` .
2021-06-15 00:49:18 -07:00
```js
assert(
2021-11-03 08:22:32 -07:00
code.match(/let lastNameLength = 0;/) & &
code.match(/const lastName = "Lovelace";/)
2021-06-15 00:49:18 -07:00
);
```
2021-07-09 21:23:54 -07:00
`lastNameLength` deve ser igual a oito.
2021-06-15 00:49:18 -07:00
```js
assert(typeof lastNameLength !== 'undefined' & & lastNameLength === 8);
```
2021-07-09 21:23:54 -07:00
Você deve estar recebendo o tamanho de `lastName` ao usar `.length` dessa forma: `lastName.length` .
2021-06-15 00:49:18 -07:00
```js
assert(code.match(/=\s*lastName\.length/g) && !code.match(/lastName\s*=\s*8/));
```
# --seed--
## --seed-contents--
```js
// Setup
2021-11-03 08:22:32 -07:00
let lastNameLength = 0;
const lastName = "Lovelace";
2021-06-15 00:49:18 -07:00
// Only change code below this line
lastNameLength = lastName;
```
# --solutions--
```js
2021-11-03 08:22:32 -07:00
let lastNameLength = 0;
const lastName = "Lovelace";
2021-06-15 00:49:18 -07:00
lastNameLength = lastName.length;
```