How do you get the 2nd highest and lowest numbers in javascript ? Without using sort or any other functions in js. I actually got highest and the lowest but I really don't know what to fix to get the 2nd numbers. this is my code
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<script type="text/javascript">
function myFunction(){
var numone = document.getElementById("num1").value;
var numtwo = document.getElementById("num2").value;
var numthree = document.getElementById("num3").value;
var numfour = document.getElementById("num4").value;
var numfive = document.getElementById("num5").value;
var array = [numone,numtwo,numthree,numfour,numfive];
var largest= 0;
for (i=0; i<=array.length;i++){
if (array[i]>largest) {
var largest=array[i];
}
}
document.getElementById("largest").value = largest;
var smallest=array[0];
for (i=0; i<array.length; i++){
if(array[i]<smallest){
var smallest=array[i];
}
document.getElementById("lowest").value = smallest;
}
}
</script>
</head>
<body>
<input type="number" id="num1">
<input type="number" id="num2">
<input type="number" id="num3">
<input type="number" id="num4">
<input type="number" id="num5">
<button type="button" onclick="myFunction()" class="btn btn-default">SUBMIT</button>
<input type="text" id="largest" disabled>
<input type="text" id="lowest" disabled>
<script type="text/javascript">
myFunction();
</script>
</body>
</html>