-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathmain.js
More file actions
202 lines (134 loc) · 5.94 KB
/
Copy pathmain.js
File metadata and controls
202 lines (134 loc) · 5.94 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
195
196
197
198
199
200
201
202
// remember to relax and ask for help when you need it (only from staff)
// YOU CAN ONLY USE MDN AS A RESOURCE
// https://developer.mozilla.org/en-US/docs/Web/JavaScript
// NOTE: you are accountable for your styling, so make sure your styling is good.
// ANOTHER NOTE: please use the console to test your code :)
//==============================================================================
/* Q1 */
//==============================================================================
//lets make an employee profile using closures
function employee(name, salary) {
function addFriend (otherEmloyee) {
return ["name"] + otherEmloyee;
}
function sayMyName (){
return name;
}
function sayHello (employee){
return "hello" + name;
}
function increaseSalary(n) {
salary = n + salary;
return salary;
}
return {sayMyName: sayMyName(),
sayHello: sayHello(),
salary: salary,
increaseSalary: increaseSalary(n),
addFriend: addFriend(otherEmloyee)
}
}
var employeeA = employee("jack", 100);
var employeeB = employee("Mark", 200);
var employeeC = employee("Sara", 150);
//create a function when invoked returns the name of that employee.
// employeeA.sayMyName(); // "jack"
// employeeB.sayMyName(); // "Mark"
//now modify that closure and add a function that says hello to the employee name;
// employeeA.sayHello(); // hello jack
// employeeB.sayHello(); // hello Mark
//modify your closure and add function increaseSalary that increases the salary for the employee by n value and return it.
//employeeA.increaseSalary(50); // "your salary is 150$"
//how about we let jack and mark meet togther!
//modify your closure and add function addFriend that accepts an object as a parameter, and let jack meets his friends.
// employeeA.addFriend(employeeB); // "you just became friend with Mark"
// employeeA.addFriend(employeeC); // "you just became friend with Mark and Sara"
//modify your closure to tell mark how many friends does he have.
// employeeA.listFriends(); // "you have 2 friends"
//=============================================================================
/* Q2 */
//=============================================================================
//lets create a pet class using OOP concept,
// a - we need to create the pets (lets create only one for now), the invocation should take the name of the pet.
// b - we need function to add the other info for the pet, called addInfo function. Make sure your functions unneeded memory space
// pet1.addInfo(age, owner, gender, species);
// c- create another function to increase the pet age by n value.
// d - create a variable called availability with the default state as false, then create another function to check the pet state, returns true if the pet is available and false if it's not
// f- in order to change the state of the pet, create a function called changeState, when called it will make the pet avaliablity true,
// and when called again it will make it false.
// Write your code here .....
function pet(name){
var obj = {};
obj.name = name;
return obj;
}
var pet1 = Pet("doggy");
function addInfo(age, owner, gender, species) {
obj.age = age;
obj.owner = owner;
obj.gender = gender;
obj.species = species;
}
function increaseAge (n){
this.age = this.age + n;
return this.age;
}
var availability = function(name) {
if (name = this.name) {
return true
}
return false;
}
// Now, to make sure that you are actually reading, make a comment below this and type: Yes I am
YES I AM
//=============================================================================
/* Q3 */
//=============================================================================
function each(coll, f) {
if (Array.isArray(coll)) {
for (var i = 0; i < coll.length; i++) {
f(coll[i], i);
}
} else {
for (var key in coll) {
f(coll[key], key);
}
}
}
function reduce(array, f, acc) {
if (acc === undefined) {
acc = array[0];
array = array.slice(1);
}
each(array, function (element, i) {
acc = f(acc, element, i);
});
return acc;
}
// Use the updated version of reduce to write a function max that returns the maximum number in an array of numbers.
// Write your code here .....
function max(arr) {
return reduce(arr, function(arr, element, i){
if (x )
})
}
//================================================================================
/* Q4 */
//================================================================================
// you can only use MDN as a resource in case you need one (https://developer.mozilla.org/en-US/docs/Learn/HTML).
// 1-Create a new html file called html_yourname.html and do the following:
// a. Change the title to : My easy Assessment.
// d. Add horizital line.
// e. Create a new div with id myInfo.
// 1. Add header : HTML is Eazy
// 2. Add the following paragraph:
// HyperText Markup Language (HTML) is the standard markup language for creating web pages and web applications.
// f. create an input text and a button called Add.
// Create css file and link it to your HTML file, and write css code for the following:
// a. Change the background color for the whole page.
// b. Change the font family for the header of the page.
// c. Enlarge the input text (both: width & height).
// 2. Connect jQuery library to the HTML file.
// 3. Write javascript function when user type text inside the input text and click the "Add"
// button it will add the text to the ul element.
// Good Luck :))