+ 2
Sorting in decreasing order. Logical this code seems correct. What do i mis?
var array =[]; for (i = 0; i < 5; i++) { array[i] = Number(prompt("Press the " + (i +1) + " number")); } for(j = 0; j < array.length - 1; j++) { var h = 0; for(i = 0+h; i < array.length; i++) { var k = 0; var max = array[j]; if (max < array[i]) { max = array[i]; k = i; } } h++; var exchange = array[j]; array[j] = max; array[k] = exchange; }
7 Answers
+ 1
var array =[];
for (i = 0; i < 5; i++) {
array[i] = Number(prompt("Press the " + (i +1) + " number"));
}
for(j = 0; j < array.length - 1; j++) {
var k = j;
var max = array[j];
for(i = j+1; i < array.length; i++) {
if (max < array[i]) {
max = array[i];
k = i;
}
}
var exchange = array[j];
array[j] = max;
array[k] = exchange;
}
document.write(array);
+ 22
Should the last line be array[j]=exchange?
I'm not sure though đ
k is declared within the previous loop.
+ 2
document.write(array);
+ 1
And yes i know about method "sort()".
+ 1
No, will not work.
+ 1
When i trying click to the "like" it writes " no conection". So i cant give you like or unlike)))
+ 1
Now it working) thank you Yasmin.