freeCodeCamp/curriculum/challenges/italian/02-javascript-algorithms-an.../basic-javascript/find-the-length-of-a-string.md

1.5 KiB

id title challengeType videoUrl forumTopicId dashedName
bd7123c9c448eddfaeb5bdef Trovare la lunghezza di una stringa 1 https://scrimba.com/c/cvmqEAd 18182 find-the-length-of-a-string

--description--

Puoi trovare la lunghezza di un valore String scrivendo .length dopo la variabile stringa o il stringa letterale.

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

Il valore 10 sarà visualizzato nella console.

Ad esempio, se avessimo creato una variabile const firstName = "Ada", potremmo scoprire quanto è lunga la stringa Ada utilizzando la proprietà firstName.length.

--instructions--

Usa la proprietà .length per contare il numero di caratteri nella variabile lastName e assegnarla a lastNameLength.

--hints--

Non dovresti cambiare le dichiarazioni della variabile nella sezione // Setup.

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

lastNameLength dovrebbe essere uguale a 8.

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

Dovresti ottenere la lunghezza di lastName utilizzando .length in questo modo: 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;