1.5 KiB
1.5 KiB
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
bd7123c9c450eddfaeb5bdef | Usare la notazione parentesi per trovare l'n-esimo carattere in una stringa | 1 | https://scrimba.com/c/cWPVJua | 18343 | use-bracket-notation-to-find-the-nth-character-in-a-string |
--description--
Puoi usare la notazione a parentesi anche per ottenere il carattere in altre posizioni all'interno di una stringa.
Ricorda che i computer iniziano a contare da 0
, quindi il primo carattere è in realtà il carattere zero.
Esempio:
var firstName = "Ada";
var secondLetterOfFirstName = firstName[1];
secondLetterOfFirstName
dovrebbe acere un valore stringa d
.
--instructions--
Cerchiamo di impostare thirdLetterOfLastName
per eguagliare la terza lettera della variabile lastName
usando la notazione parentesi.
Suggerimento: Prova a guardare l'esempio qui sopra se ti blocchi.
--hints--
La variabile thirdLetterOfLastName
dovrebbe avere il valore di v
.
assert(thirdLetterOfLastName === 'v');
Dovresti usare la notazione a parentesi.
assert(code.match(/thirdLetterOfLastName\s*?=\s*?lastName\[.*?\]/));
--seed--
--after-user-code--
(function(v){return v;})(thirdLetterOfLastName);
--seed-contents--
// Setup
var lastName = "Lovelace";
// Only change code below this line
var thirdLetterOfLastName = lastName; // Change this line
--solutions--
var lastName = "Lovelace";
var thirdLetterOfLastName = lastName[2];