You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 11_Working_with_Arrays/challenge.js
+58-1Lines changed: 58 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,6 @@
1
+
'use-strict';
1
2
/*
2
-
------------Coding Challenge 1------------
3
+
? ------------Coding Challenge 1------------
3
4
4
5
Julia and Kate are doing a study on dogs. So each of them asked 5 dog owners about their dog's age, and stored the data into an array (one array for each). For now, they are just interested in knowing wether a dog is an adult or a puppy. A dog is an adult if it is at least 3 years old, and it's a puppy if it's less than 3 years old.
Let's go back to Julia and Kate's study about dogs. This time, they want to convert dog ages to human ages and calculate the average age of the dogs in their study.
51
+
52
+
Create a function `calcAverageHumanAge`, which accepts an array of dog's ages, and does the following things:
53
+
54
+
1. Calculate the dog age in human years using the following formula: if the dog is <= 2 years old, humanAge = 2 * dogAge. If the dog is > 2 years old, humanAge = 16 + dogAge * 4.
55
+
56
+
2. Exclude all dogs that are less than 18 human years old (which is the same as keeping dogs that are at least 18 years old)
57
+
58
+
3. Calculate the average human age of all adult dogs (you should already know from other challenges how we calculate averages 🙂)
0 commit comments