-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
215 lines (143 loc) · 4.57 KB
/
Copy pathapp.js
File metadata and controls
215 lines (143 loc) · 4.57 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
var Person = function(name,yearOfBirth,job){
this.name = name;
this.yearOfBirth = yearOfBirth;
this.job = job;
};
var john = new Person('John',1990,'Teacher');
// console.log(typeof(john));
// console.log(typeof(Person));
// console.log(typeof(Object));
// Object.Create
// var personProto = {
// firstname : 'Harmandeep',
// lastname : 'Singh',
// calculateAge : function(){
// console.log(2018 - this.yearOfBirth)
// }
// };
// var john = Object.create(personProto);
// john.name = 'John';
// john.yearOfBirth = '1990';
// john.job = 'teacher';
// var jane = Object.create(personProto,{
// name : {value : 'Jane'},
// yearOfBirth : {value : '1990'},
// job : {value : 'Teacher'}
// });
// FIRST CLASS FUNCTIONS
// Passing functions as arguments
// var years = [1990,1993,2002,2009,1989,1976];
// var calcFunction = function(arr,fn){
// tempArr = [];
// for(var i = 0; i < arr.length; i++){
// tempArr[i] = fn(arr[i]);
// }
// return tempArr;
// }
// function calcAge(el){
// return 2018 - el;
// }
// function calcHeartRate(el){
// return Math.round(206.6 - (0.67*calcAge(el)));
// }
// var ages = calcFunction(years,calcAge);
// var heartRate = calcFunction(years,calcHeartRate);
// console.log(ages);
// console.log(heartRate);
// Returning function from a function
// function interviewQuestion(job){
// if(job === 'designer'){
// return function(name){
// console.log('Hi ' + name + ', What do you know about UX Designing?');
// }
// } else if (job === 'teacher'){
// return function(name){
// console.log('How much year of experience do you have ' + name);
// }
// } else{
// return function(name){
// console.log('What do you do ? '+ name);
// }
// }
// }
// var teacherQuestion = interviewQuestion('teacher');
// teacherQuestion('Manini');
// interviewQuestion('designer')('Rohan');
// Call, Apply and Bind
// var years = [1990,1993,2002,2009,1989,1976];
var calcFunction = function(arr,fn){
tempArr = [];
for(var i = 0; i < arr.length; i++){
tempArr[i] = fn(arr[i]);
}
return tempArr;
}
function calcAge(el){
return 2018 - el;
}
function calcHeartRate(el){
return Math.round(206.6 - (0.67*calcAge(el)));
}
function fullAge(limit,el){
return el >= limit;
}
var ages = calcFunction(years,calcAge);
var fullAgeIndia = calcFunction(ages, fullAge.bind(this,20));
console.log(fullAgeIndia);
// Coding Challenge
// Self calling function
// (function(){
// function quizQuestions(question,options,ans){
// this.question = question;
// this.options = options;
// this.ans = ans;
// }
// quizQuestions.prototype.display = function(){
// console.log(this.question);
// for(var i = 0; i < this.options.length; i++){
// console.log(i + ': ' + this.options[i] + '\n');
// }
// }
// quizQuestions.prototype.checkAnswer = function(ans,callback){
// var sc;
// if(this.ans === ans){
// console.log('Correct answer!!!');
// sc = callback(true);
// } else {
// console.log('Wrong Answer!!! Please try again :(');
// sc = callback(false);
// }
// this.displayScore(sc)
// }
// quizQuestions.prototype.displayScore = function(score){
// console.log('Your Current Score : ' + score);
// console.log('---------------------------------');
// }
// var q1 = new quizQuestions('What is the capital of India?',
// ['Delhi','Mumbai','Chandigarh'],0);
// var q2 = new quizQuestions('How many planets are the in the solar system?',
// ['9','8','10','5'],1);
// var q3 = new quizQuestions('Is JavaScript is client side or server side language?',
// ['client','server','both'],2);
// function score(){
// var sc = 0;
// return function(correct){
// if(correct){
// sc++;
// }
// return sc;
// }
// }
// var keepScore = score();
// function nextQuestion(){
// question = [q1,q2,q3];
// var n = Math.floor(Math.random()*question.length);
// question[n].display();
// var answer = prompt('Enter your answer : ');
// if(answer !== 'exit'){
// question[n].checkAnswer(parseInt(answer),keepScore);
// nextQuestion();
// }
// }
// nextQuestion();
// })();