I'm having an issue returning the array value from the multiply function. I would like to know what's the best approach for this? Appreciate any help. Thanks
<head>
<script>
function test() {
let list1 = [ 17, 8, 9, 5, 20 ];
let list2 = [ 12, 4, 8, 15, 17, 5, 20, 11 ];
// Test the multiply function by calling it two times.
let mult1 = multiply(list1,3);
let mult2 = multiply(list2,2);
function multiply(list,x) {
var myArray = [0];
for (i = 0; i < list.length; i++) {
myArray[i] = list[i] * x;
}
return myArray;
}
let output = mult1 + '<br>' + mult2;
</script>
</head>
<body>
<button type="button" click="test()">Compute</button>
<p id="output"></p>
</body>