The most viewed items
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo"></p>
<button type = "button" onclick = "findMax()">Find Max</button>
<button type = "button" onclick = "numReset()">Reset</button>
<button type = "button" onclick = "findMin()">Find Min</button>
<script>
var numbers = [200, 30, 400, 50, 1000, 70, 20, 100];
document.getElementById("demo").innerHTML = numbers.join("<br />");
function jsMax(arr){
var len = arr.length;
var max = -Infinity;
while(len--){
if(arr[len] > max){
max = arr[len];
}
}
return max;
}
function jsMin(arr){
var len = arr.length;
var min = Infinity;
while(len--){
if(arr[len] < min){
min = arr[len];
}
}
return min;
}
function findMax(){
document.getElementById("demo").innerHTML = jsMax(numbers);
}
function findMin(){
document.getElementById("demo").innerHTML = jsMin(numbers);
}
function numReset(){
document.getElementById("demo").innerHTML = numbers.join("<br/>");
}
</script>
</body>
</html>
No comment to show.