I have a function that takes an array and a target number. The goal is two generate any two random numbers from the array and sum them up. If the sum of the two random integers is equal to the target number, I then have to return the index of the two random numbers in the array.
Here is my code so far, I keep getting a stderr. How do you recommend I go about this.
function twoSum (numbers, target) {
let numIdx = [];
let sum = 0;
let firstValue = 0;
let secValue = 0
while(sum !== target) {
firstValue = Math.floor(Math.random() * numbers.length);
secValue = Math.floor(Math.random() * numbers.length);
sum = firstValue + secValue;
if (sum === target) {
numIdx.push(numbers[firstValue])
numIdx.push(numbers[secValue])
return numIdx
}
}
}