-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17_checkForObjectKey.js
47 lines (41 loc) · 1.01 KB
/
17_checkForObjectKey.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
// Check if an Object has a Property
let foods = {
apples: 25,
oranges: 32,
plums: 28,
bananas: 13,
grapes: 35,
strawberries: 27
};
/* There are two ways to check for keys or properties
in an object: the hasOwnProperty() method and the in
keyword. */
console.log(foods.hasOwnProperty('oranges')); // true
console.log('oranges' in foods); // true
/* Finish writing the function so that it returns true if the
object passed to it contains all four names, Alan, Jeff,
Sarah, and Ryan and returns false otherwise. */
let users = {
Alan: {
age: 27,
online: true
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: true
},
Ryan: {
age: 19,
online: true
}
};
function isEveryoneHere(userObj) {
// Only change code below this line
return 'Alan' in userObj && 'Jeff' in userObj && 'Sarah' in userObj && 'Ryan' in userObj
// Only change code above this line
}
console.log(isEveryoneHere(users));