forked from DevMountain/basecamp-assessment-ii
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assessment.js
94 lines (71 loc) · 2.82 KB
/
assessment.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
// #1 Create an object called 'me' that has three keys, 'firstname' 'age' and 'state'. Assign the keys the appropriate values.
var me = {
firstname: "Skyler",
age: "24",
state: "Utah"
};
// #2 Add a new key/value pair to the me object using dot notation. The new key should be 'favecolor' and set it to your favorite color as a string
me.faveColor = "blue";
// #3 Below is an object, 'message'. Below it, add a 'text' key using bracket notation and assign it a string of whatever you would like.
//DON'T TOUCH THE CODE BELOW
var message = {
date: new Date(),
userName: me.firstname
}
//DON'T TOUCH THE CODE ABOVE
message["text"] = "cheese";
// #4 Create an object called 'adjustCount' and create two methods. One called 'upVote' and one called 'downVote'. upVote should take in a number and add one to it and downVote should take in a number and minus one from it.
var adjustCount = {
'upVote': function(num){
return num + 1;
},
'downVote': function(num){
return num -1;
}
}
// #5 Create an array called 'myFriends' with four of your friends names
var myFriends = [
"Eric", "Devin", "Collin", "Austin"
];
// #6 Add a fifth friends name to the end of your myFriends array
myFriends.push("Petie");
// #7 Create a 'myArrayCopy' variable. It should equal the myArray variable. Use the built in JavaScript method to create a copy.
//DON'T TOUCH THE CODE BELOW
var myArray = [1, 2, 3, 4]
//DON'T TOUCH THE CODE ABOVE
var myArrayCopy = myArray.slice(0,4);
// #8 Below is a array, myNumbers. Create a function called 'evensOnly' that returns the 'evensArray' of only even numbers
//DON'T TOUCH THE CODE BELOW
var myNumbers = [333, 1, 4, 5, 511, 34, 88, 77, 222]
//DON'T TOUCH THE CODE ABOVE
var evensArray = [];
function evensOnly (){
for (i = 0; i < myNumbers.length; i++){
if (myNumbers[i] % 2 === 0){
console.log(myNumbers[i]);
evensArray.push(myNumbers[i]);
}
} return evensArray;
};
// #9 Using filter(), return only your friends of the array of people below. Assign it to a variable called 'trueFriends'.
var peopleIknow = [
{ name: "Steve", friend: true },
{ name: "Dan", friend: false },
{ name: "Bart", friend: true },
{ name: "Sarah", friend: false },
{ name: "Michelle", friend: false },
{ name: "Holly", friend: true }
]
var trueFriends = peopleIknow.filter(function(person){
if (person.friend){
return true;
} else {return false}
}); console.log(trueFriends);
// #10 create a function caled indexFinder and loop ove the randomNumbers array below and return a new array called 'indexes' with just their indexes. Be sure to invoke indexFinder.
let randomNumbers = [1, 3453, 34, 456, 32, 3, 2, 0]
var indexes = [];
function indexFinder (){
for (i = 0; i < randomNumbers.length; i++){
indexes.push(randomNumbers.indexOf(randomNumbers[i]));
} return indexes;
} indexFinder();