-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-EJS-Ch1-values-and-operators.js
136 lines (110 loc) · 3.22 KB
/
01-EJS-Ch1-values-and-operators.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
var assert = require('assert');
var ___ = undefined;
/*
* To complete the exercise, replace underscores in the
* code below with appropriate values to make the tests
* pass.
*
* See README.md for installing the test library and
* running the tests.
*/
describe("Numbers", function(){
it("can be added together", function(){
var val = 34 + ___ ;
assert.strictEqual( val, 40);
});
it("can be defined using scientific notation", function(){
assert.strictEqual(3e8 * 3e8, ___);
});
it("are floating point", function(){
assert.strictEqual(1/2, ___);
});
it("will turn into NaN under certain conditions", function(){
assert(isNaN( 1.2 ));
});
it("that are NaN are not equal to themselves", function(){
assert.equal(NaN === NaN, ___);
});
});
describe("Operators", function(){
it("follow the same rule of precedence as mathematics", function(){
assert.strictEqual( 10 * 3 + 4, ___ );
assert.strictEqual( 10 * (3 + 4), ___ );
});
it("can be used to find the remainder or modulo", function(){
assert.strictEqual(10 % 3, ___)
});
it("can be used to compare numbers", function(){
assert.strictEqual(1>2, ___);
assert.strictEqual(1<2, ___);
});
it("can be used to compare strings", function(){
assert("Hello" > ___);
});
describe("Unary operators", function(){
it("take only one argument", function(){
assert.strictEqual(typeof 1.2, ___);
assert.strictEqual(-(6+4), ___);
});
it("can be used to increment a number", function(){
var num = 34;
num++;
assert.strictEqual(num, ___);
});
it("can be used to decrement a number", function(){
var num = 34;
num++;
assert.strictEqual(num, ___);
});
it("are applied differently as postfix or prefix", function(){
var x = 10;
assert.equal(--x, ___);
x = 10;
assert.equal(x--, ___);
x = 10;
assert.equal(++x, ___);
x = 10;
assert.equal(x++, ___);
});
});
describe("Logical operators", function(){
it("apply to boolean values", function(){
assert(true && ___);
assert(false || ___);
assert(!___);
});
it("will short-circuit their arguments", function(){
assert.strictEqual( "Hello" || "Danger", ___);
assert.strictEqual( "Hello" && "Danger", ___);
});
});
describe("The ternary operator", function(){
it("changes its resulting value based on a condition", function(){
assert.strictEqual(___?3:4, 3);
assert.strictEqual(false?"Brie":___, "Gouda cheese");
assert.strictEqual(true?___:"Helicopter", "Hovercraft");
});
});
});
describe("Strings", function(){
it("can be concatenated together", function(){
var greeting = "Hello, " + ___;
assert.strictEqual(greeting, "Hello, Awesome.");
});
});
describe("Javascript", function(){
it("does really weird shit sometimes", function(){
// see https://www.destroyallsoftware.com/talks/wat
assert.strictEqual(100 * null, ___);
assert.strictEqual("4" + 3 , ___);
assert.strictEqual("4" - 3 , ___);
assert.strictEqual("4" * 3 , ___);
assert.strictEqual(false == 0, ___);
});
it("gives the special '===' comparison operator", function(){
assert.strictEqual(0 == false, ___);
assert.strictEqual("" == false, ___);
assert.strictEqual(0 === false, ___);
assert.strictEqual("" === false, ___);
});
})