Certainly! You can use JavaScript to find the minimum and maximum elements in an array. Here’s an example code snippet with HTML:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Find Min and Max</title> </head> <body> <script> // Function to find minimum and maximum elements in an array function findMinAndMax(arr) { if (arr.length === 0) { return { min: undefined, max: undefined }; } let min = arr[0]; let max = arr[0]; for (let i = 1; i < arr.length; i++) { if (arr[i] < min) { min = arr[i]; } if (arr[i] > max) { max = arr[i]; } } return { min, max }; } // Example usage const numbers = [3, 1, 7, 4, 2, 8, 5]; const result = findMinAndMax(numbers); console.log("Array:", numbers); console.log("Minimum:", result.min); console.log("Maximum:", result.max); </script> </body> </html>
In this example, the `findMinAndMax` function takes an array as input and iterates through it to find the minimum and maximum elements. The result is then logged to the console. You can adapt this code to display the result on your webpage as needed.