Find greatest value in array (in set of integers)
<p>My friend asked me to help him with homework. And I'm stuck. Here is algorithm: user must enter in first prompt box number of elements in array. Then, he will get prompt box for each number to enter. Now, output must be greatest number in array. But that simply don't work. With my code below, I get always element who has greatest first digit. (it's doesn't matter if number is negative or positive, code don't work as it should)</p>

<p>Here is my code (it even doesn't work in jsfiddle, just in my file o.O)</p>

<pre><code>&lt;button onclick="duzinaNiza()"&gt;Do it!&lt;/button&gt;
</code></pre>

<p>and here is JavaScript</p>

<pre><code>function duzinaNiza() {
    var brClanova = prompt("Enter the number of array elements:");

    if (brClanova &gt; 0) {
        var niz = new Array();

        for (i=0; i&lt;brClanova; i++) {
            var redniBr = i+1;
            niz[i] = prompt("Enter "+ redniBr +". array number:");
            \\ prompt for geting each array element
        }


        var maximum = niz[0];

        for (a=0; a&lt;brClanova; a++) {

            if (maximum &lt; niz[a]) {
                maximum = niz[a];
            }
        }

        document.write("Greatest value in array is: " + maximum);   
    }
}
</code></pre>

<p>My friend's proffesor don't want to use functions for sorting arrays, this must be done with loops.</p>

<p>P.S. Yeah, I know... But don't ask about document.write thing, it must be printed in that way...</p>
