2.1 KiB
2.1 KiB
id, title, challengeType, videoUrl, forumTopicId, localeTitle
id | title | challengeType | videoUrl | forumTopicId | localeTitle |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244aa | Understanding Uninitialized Variables | 1 | https://scrimba.com/c/cBa2JAL | 18335 | 理解未初始化的变量 |
Description
undefined
。当你对一个值为undefined
的变量进行运算操作的时候,算出来的结果将会是NaN
,NaN
的意思是"Not a Number"。当你用一个值是undefined
的变量来做字符串拼接操作的时候,它会输出字符串"undefined"
。
Instructions
a
、b
、c
,并且分别给他们赋值:5
、10
、"I am a"
,这样它们值就不会是undefined
了。
Tests
tests:
- text: <code>a</code>应该被定义,并且值为<code>6</code>。
testString: assert(typeof a === 'number' && a === 6);
- text: <code>b</code>应该被定义,并且值为<code>15</code>。
testString: assert(typeof b === 'number' && b === 15);
- text: <code>c</code>的值不能包含<code>undefined</code>,应该为 "I am a String!"。
testString: assert(!/undefined/.test(c) && c === "I am a String!");
- text: 不要修改第二条注释下的代码。
testString: assert(/a = a \+ 1;/.test(code) && /b = b \+ 5;/.test(code) && /c = c \+ " String!";/.test(code));
Challenge Seed
// Initialize these three variables
var a;
var b;
var c;
// Do not change code below this line
a = a + 1;
b = b + 5;
c = c + " String!";
After Test
(function(a,b,c){ return "a = " + a + ", b = " + b + ", c = '" + c + "'"; })(a,b,c);
Solution
var a = 5;
var b = 10;
var c = "I am a";
a = a + 1;
b = b + 5;
c = c + " String!";