freeCodeCamp/curriculum/challenges/italian/02-javascript-algorithms-an.../basic-javascript/use-bracket-notation-to-fin...

1.6 KiB

id title challengeType videoUrl forumTopicId dashedName
bd7123c9c452eddfaeb5bdef Usare la notazione parentesi per trovare l'n-ultimo carattere dalla fine di una stringa 1 https://scrimba.com/c/cw4vkh9 18344 use-bracket-notation-to-find-the-nth-to-last-character-in-a-string

--description--

È possibile utilizzare lo stesso principio che abbiamo appena usato per recuperare l'ultimo carattere in una stringa per recuperare il carattere n-ultimo dalla fine.

Ad esempio, puoi ottenere il valore della terzultima lettera della stringa var firstName = "Augusta" usando firstName[firstName. lunghezza - 3]

Esempio:

var firstName = "Augusta";
var thirdToLastLetter = firstName[firstName.length - 3];

thirdToLastLetter dovrebbe avere un valore stringa s.

--instructions--

Usa la notazione a parentesi per trovare il penultimo carattere nella stringa lastName.

Suggerimento: Prova a guardare l'esempio qui sopra se ti blocchi.

--hints--

secondToLastLetterOfLastName dovrebbe essere la lettera c.

assert(secondToLastLetterOfLastName === 'c');

Dovresti usare .length per ottenere la penultima lettera.

assert(code.match(/\.length/g).length > 0);

--seed--

--after-user-code--

(function(v){return v;})(secondToLastLetterOfLastName);

--seed-contents--

// Setup
var lastName = "Lovelace";

// Only change code below this line
var secondToLastLetterOfLastName = lastName; // Change this line

--solutions--

var lastName = "Lovelace";
var secondToLastLetterOfLastName = lastName[lastName.length - 2];