forked from turingschool-examples/javascript-foundations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbirthdays.js
55 lines (50 loc) · 1.49 KB
/
birthdays.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
function createBirthday(name, month, day) {
var birthdayObj = {
name: name,
month: month,
day: day,
};
return birthdayObj;
}
function celebrateBirthday(birthdayObj) {
var birthdayPerson = birthdayObj.name;
var birthdayMonth = birthdayObj.month;
var birthdayDay = birthdayObj.day;
return `Today is ${birthdayMonth}/${birthdayDay}! Happy birthday, ${birthdayPerson}!`;
}
// look at the array
// loop through the array
// each iteration is an object
// in the object, look at the month
// if the month is (2)Feb, count how many and return
// if the month is (5)May, count how many and return
// if the month is (12)Dec, count how many and return
function countBirthdays(arrayBirthdays, month) {
let counter = 0;
console.log(arrayBirthdays);
console.log(month);
for (var i = 0; i < arrayBirthdays.length; i++) {
if (arrayBirthdays[i].month === month) {
counter += 1;
}
}
return counter;
}
// function countBirthdays(arrayBirthdays) {
// let counterFeb = 0;
// let counterMay = 0;
// let counterDec = 0;
// for (var i = 0; i < arrayBirthdays.length; i++) {
// if (arrayBirthdays[i].month === 2) {
// var febBdays = (counterFeb += 1);
// return febBdays;
// } else if (arrayBirthdays[i].month === 5) {
// var mayBdays = (counterMay += 1);
// return mayBdays;
// } else {
// var decBdays = counterDec;
// return decBdays;
// }
// }
// }
module.exports = { createBirthday, celebrateBirthday, countBirthdays };