Hi everyone! I am trying to get a line break after every element in my array. In other words, the names I enter I want it to look like:
Name
Name
Name
etc.
Not like: Name, Name, Name, etc.
I have posted my code. Also if anyone see a more efficient way of this script, let me know.
Thanks!
[code]
<?xml version = “1.0” encoding = “utf-8”?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHMTL 1.0 Strict//EN”
“http://www.w3.org/TR/xhtmll/DTD/xhtmll-strict.dtd”>
<!– ssort.html
Clint Sharp CS3010-001 XHTML/Javascript Selection Sort
–>
<html xmlns = “http://www.w3.org/1999/xhtml”>
<head>
<title>Clint Sharp’s XHTML/Javascript Selection Sort</title>
<script type = “text/javascript”>
<!–
function displayNames() {
document.write(selectionSort(nameArray));
}
function swap(items, firstIndex, secondIndex){
var temp = items[firstIndex];
items[firstIndex] = items[secondIndex];
items[secondIndex] = temp;
}
function selectionSort(items){
var len = items.length,min;
for (i=0; i < len; i++){
min = i;
for (j=i+1; j < len; j++){
if (items[j] < items[min]){
min = j;
}
}
if (i != min){
swap(items, i, min);
}
}
return items;
}
var nameArray = [];
var nameEntry = ”;
do {
nameEntry = prompt(“Enter a name. Press cancel or leave prompt field empty to finish.”);
if (nameEntry === “” || nameEntry === null) {
break;
} else {
nameArray.push(nameEntry);
}
} while (1);
displayNames();
//–>
</script>
</head>
<body>
</body>
</html>