Hey guys, OK first of all this IS an assignment question so although I really appreciate your help please try to point me in the right direction as I don't want to get into trouble!
I am trying to write a bubblesort function and test, so far I have constructed the following but it is not working when run in a browser, would anyone mind having a quick read to see if im missing something obvious? thanks!
HTML Code:<HTML> <HEAD> <TITLE> A program to sort an array using a bubble sort </TITLE> <SCRIPT> /* A function to sort an array Function takes an array of numbers as an argument. Function returns a new array with the same elements as the argument array, sorted into ascending order */ function bubbleSort(arrayToSort) { // declare and initialise a variable to hold the length of the argument array var length = arrayToSort.length; //declare an array to be returned by the function var returnArray = new Array(length); //copy each element of the argument array to the return array for (var i = 0; i < length; i = i + 1) { returnArray[i] = arrayToSort[i]; } // PLACE YOUR CODE FOR THE FUNCTION HERE var counter, value, tempStore; /*the counter sets the number of passes using the total length */of the array, this way it can deal with an array of any length for (counter = 0; counter < returnArray.length; counter++) { //here the starting position of the array is set for (value = 0; value < (returnArray.length-1); value++; { if (returnArray[value) > returnArray[value+1]) { /*the value to be replaced is put in a temp holder */to prevent the value from bing lost holder = returnArray[returnArray+1]; returnArray[value+1] = returnArray[value]; returnArray[value] = holder; } } return returnArray; } /* a function for testing the bubbleSort() function. Function assigns an array to a variable Displays elements of unsorted array in order Invokes bubbleSort() function with the array as the argument Displays elements of sorted array in order Function takes no arguments. Function returns no value. */ function bubbleTest() { var unsortedArray; var sortedArray; // the array of values to be sorted unsortedArray = [9,7,2,10,1,4,8,6,5,3]; // PLACE YOUR FUNCTION CODE HERE document.write('Unsorted Array: ' + unsortedArray + 'BR'); arrayToSort = unsortedArray; bubbleSort(); document.write('Sorted Array: ' returnArray); } // invoke bubbleTest() to test the bubbleSort() function bubbleTest(); </SCRIPT> </HEAD> <BODY> </BODY> </HTML>