Interactive online courses HTML Academy
2026-03-09 12:27 Diff
  • script.js

JavaScript

var usersByDay = [1, 2, 3, 4, 5, 6]; console.log(usersByDay); if (usersByDay.length % 2 !== 0) { var medianIndex = (usersByDay.length - 1) / 2; console.log(medianIndex); var median = usersByDay[medianIndex]; console.log(median); }

Thanks! We’ll fix everything at once!

Result

  1. In the alternative branch of the condition, add the variable leftIndex with the value usersByDay.length / 2 - 1.
  2. And variable rightIndex with value usersByDay.length / 2.
  3. Log both variables in the console.
  4. In the same condition branch, add variable median with value (usersByDay[leftIndex] + usersByDay[rightIndex]) / 2.
  5. Log it in the console as well.