1.7 KiB
1.7 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
| id | title | challengeType | videoUrl | forumTopicId | dashedName |
|---|---|---|---|---|---|
| 56533eb9ac21ba0edf2244aa | Comprendere le variabili non inizializzate | 1 | https://scrimba.com/c/cBa2JAL | 18335 | understanding-uninitialized-variables |
--description--
Quando vengono dichiarate delle variabili in JavaScript, esse hanno un valore iniziale undefined. Se esegui un'operazione matematica su una variabile undefined, il risultato sarà NaN che significa "Not a Number" (non è un numero). Se concateni una stringa con una variabile undefined, otterrai una stringa letterale undefined.
--instructions--
Inizializza le tre variabili a, b e c con 5, 10, e "I am a" rispettivamente, in modo che non siano undefined.
--hints--
a dovrebbe essere definito e avere il valore 6.
assert(typeof a === 'number' && a === 6);
b dovrebbe essere definito e avere il valore 15.
assert(typeof b === 'number' && b === 15);
c non dovrebbe contenere undefined e dovrebbe avere un valore stringa I am a String!
assert(!/undefined/.test(c) && c === 'I am a String!');
Non modificare il codice sotto il commento specificato.
assert(
/a = a \+ 1;/.test(code) &&
/b = b \+ 5;/.test(code) &&
/c = c \+ " String!";/.test(code)
);
--seed--
--after-user-code--
(function(a,b,c){ return "a = " + a + ", b = " + b + ", c = '" + c + "'"; })(a,b,c);
--seed-contents--
// Only change code below this line
var a;
var b;
var c;
// Only change code above this line
a = a + 1;
b = b + 5;
c = c + " String!";
--solutions--
var a = 5;
var b = 10;
var c = "I am a";
a = a + 1;
b = b + 5;
c = c + " String!";