Skip to content
Advertisement

Difficulty trying to sort 10 numbers inputted by a user. Must use arrays and a separate method for sorting

My program isn’t sorting the numbers at all. It displays them in the order they were initially entered. It must sort them from smallest to largest number. The code below should find the largest number in the array and swap it with the last .the code is below:

JavaScript

Advertisement

Answer

I believe your problem is here:

JavaScript

array.length is not less than 0 so the for loop never runs. You probably wanted

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement