- script.js
JavaScript
var usersByDay = [1, 2, 3, 4, 5];
console.log(usersByDay);
Result
Goalscompleted
- At the end of the program, add a check for an odd number of elements in the array:
usersByDay.length % 2 !== 0
. - If the condition is met, add a variable
medianIndex
with value(usersByDay.length - 1) / 2
. - Log this variable in the console.
- In the same condition branch, add variable
median
with valueusersByDay[medianIndex]
. - Log it in the console as well.
Comments