Interactive online courses HTML Academy
2026-03-09 10:53 Diff
  • script.js

JavaScript

var usersByDay = [4, 2, 1, 3]; console.log(usersByDay); var currentIndex = 0; var minValue = usersByDay[currentIndex]; for (var j = currentIndex + 1; j <= usersByDay.length - 1; j++) { if (usersByDay[j] < minValue) { minValue = usersByDay[j]; } } console.log('Minimum element: ' + minValue);

Thanks! We’ll fix everything at once!

Result

  1. Inside the condition after the variable minValue, save the value usersByDay[currentIndex] to variable swap. Write the remaining code inside the condition.
  2. On the next line in usersByDay[currentIndex], write down the minimum value.
  3. Then write value of variable swap in usersByDay[j].
  4. On the next line, log in the console: 'Swapping ' + swap + ' and ' + minValue.
  5. Below, log in the console: 'Current array: ' + usersByDay.