Skip to content

Commit 014c09c

Browse files
author
Sascha Brink
committed
Move questions to constant
1 parent c595b90 commit 014c09c

File tree

5 files changed

+54
-51
lines changed

5 files changed

+54
-51
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ <h1 class="page-header">JavaScript - Type Coercion Challenge</h1>
3232
<script src="scripts/controllers/summaryCtrl.js"></script>
3333
<script src="scripts/filters/evalFilter.js"></script>
3434
<script src="scripts/services/DataHolderService.js"></script>
35+
<script src="scripts/config/questions.js"></script>
3536
<script src="scripts/config/routeConfig.js"></script>
3637

3738

scripts/config/questions.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
angular.module("typeCoercion")
2+
.constant("questions", [
3+
'1 == 1', // returns true
4+
'"1" == 1', // returns true ("1" converts to 1)
5+
'1 == true', // returns true
6+
'0 == false', // returns true
7+
'"" == 0', // returns true ("" converts to 0)
8+
'" " == 0', // returns true (" " converts to 0)
9+
'0 == 1', // returns false
10+
'1 == false', // returns false
11+
'0 == true', // returns false
12+
'0 != false', // returns false
13+
'"" != 0', // returns false ("" converts to 0)
14+
'" " != 0', // returns false (" " converts to 0)
15+
'0 != 1', // returns true
16+
'1 != false', // returns true
17+
'0 != true', // returns true
18+
'1 === 1', // returns true
19+
'"1" === 1', // returns false ("1" is not converted)
20+
'1 === true', // returns false
21+
'0 === false', // returns false
22+
'"" === 0', // returns false ("" is not converted)
23+
'" " === 0', // returns false (" " is not converted)
24+
'0 === 1', // returns false
25+
'1 === false', // returns false
26+
'0 === true', // returns false
27+
'var x, y;\nx = {};\ny = x;\nx != y //?', // returns false (refers to same object in memory)
28+
'var x, y;\nx = {};\ny = x;\nx != {} //?', // returns true (not the same object)
29+
'var x, y;\nx = {};\ny = x;\nx == y //?', // returns true (refers to same object in memory)
30+
'var x, y;\nx = {};\ny = x;\nx == {} //?', // returns false (not the same object)
31+
'var x, y;\nx = {};\ny = x;\nx === y //?', // returns false (not the same object)
32+
'var x, y;\nx = {};\ny = x;\nx === {} //?',
33+
'if("")', // false
34+
'if("5")', // true
35+
'if(0)', // false
36+
'if(-1)', // true
37+
'if(null)', // false
38+
'if(undefined)', // false'// returns false (not the same object)
39+
'null == undefined', // returns true
40+
'null == false', // returns false
41+
'NaN == NaN' // returns false
42+
]);

scripts/controllers/summaryCtrl.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
angular.module("typeCoercion")
2-
.controller("summaryCtrl", function ($scope, $location, DataHolderService) {
3-
'use strict';
4-
$scope.tasks = DataHolderService.getTasks();
5-
$scope.results = DataHolderService.getResults();
6-
ga('send', 'pageview-result');
7-
2+
.controller("summaryCtrl", function ($scope, $location, DataHolderService) {
3+
'use strict';
4+
$scope.tasks = DataHolderService.getTasks();
5+
$scope.results = DataHolderService.getResults();
6+
ga('send', 'pageview-result');
87

98
if (!$scope.results.length) {
10-
$location.path("/");
11-
}
12-
});
9+
$location.path("/");
10+
}
11+
});

scripts/controllers/taskCtrl.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ angular.module("typeCoercion")
1515
} else {
1616
$location.path("/summary");
1717
}
18+
console.log(results);
1819

1920
};
2021

scripts/services/DataHolderService.js

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,12 @@
11
angular.module("typeCoercion")
2-
.factory("DataHolderService", function () {
2+
.factory("DataHolderService", function(questions) {
33
'use strict';
44
function shuffle(o) { //v1.0
55
for (var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
66
return o;
77
};
88
var results = [];
9-
var tasks = shuffle([
10-
'1 == 1', // returns true
11-
'"1" == 1', // returns true ("1" converts to 1)
12-
'1 == true', // returns true
13-
'0 == false', // returns true
14-
'"" == 0', // returns true ("" converts to 0)
15-
'" " == 0', // returns true (" " converts to 0)
16-
'0 == 1', // returns false
17-
'1 == false', // returns false
18-
'0 == true', // returns false
19-
'0 != false', // returns false
20-
'"" != 0', // returns false ("" converts to 0)
21-
'" " != 0', // returns false (" " converts to 0)
22-
'0 != 1', // returns true
23-
'1 != false', // returns true
24-
'0 != true', // returns true
25-
'1 === 1', // returns true
26-
'"1" === 1', // returns false ("1" is not converted)
27-
'1 === true', // returns false
28-
'0 === false', // returns false
29-
'"" === 0', // returns false ("" is not converted)
30-
'" " === 0', // returns false (" " is not converted)
31-
'0 === 1', // returns false
32-
'1 === false', // returns false
33-
'0 === true', // returns false
34-
'var x, y;\nx = {};\ny = x;\nx != y //?', // returns false (refers to same object in memory)
35-
'var x, y;\nx = {};\ny = x;\nx != {} //?', // returns true (not the same object)
36-
'var x, y;\nx = {};\ny = x;\nx == y //?', // returns true (refers to same object in memory)
37-
'var x, y;\nx = {};\ny = x;\nx == {} //?', // returns false (not the same object)
38-
'var x, y;\nx = {};\ny = x;\nx === y //?', // returns false (not the same object)
39-
'var x, y;\nx = {};\ny = x;\nx === {} //?',
40-
'if("")', // false
41-
'if("5")', // true
42-
'if(0)', // false
43-
'if(-1)', // true
44-
'if(null)', // false
45-
'if(undefined)', // false'// returns false (not the same object)
46-
'null == undefined', // returns true
47-
'null == false', // returns false
48-
'NaN == NaN' // returns false
49-
]);
9+
var tasks = shuffle(questions);
5010

5111
return {
5212
getTasks: function () {

0 commit comments

Comments
 (0)