Hi, I'm new to JS programming and I would appreciate any help or advise with helping me solve an issue that I have. I need to create a function that accepts any array of numbers and returns an array of percentage values for each number on a scale of 0 to the highest number in the array. Round any decimals to two decimal places.

I eventuality would like to call this function from its own JavaScript file and display the return array.

Array I used to test - [2, 12, 4, 7]

Output I have thus far:

12

0.16666666666666666

1

0.3333333333333333

0.5833333333333334

My logic to solve this would look something like this:

- find the largest number in the array
- take each number in the array and divide by the largest number in the array
- round each number to 2 decimal places
- output to the screen in the format of an array [16.66, 1, 33.33, 58.33]

This is what I have so far:

Code:<!DOCTYPE html> <html> <head> </head> <body> <p id="number"></p> <!-- scripts.js --> <script> var myArray = [2, 12, 4, 7]; var largestNumber = Math.max.apply(Math, myArray); document.getElementById("number").innerHTML = largestNumber; // display largest number in array for (var i=0; i < myArray.length; i++) { myArray[i] /= largestNumber; document.write(myArray[i] + "<br />"); } </script> <!-- scripts.js --> </body> </html>