Question: Add a throw statement to the processNumbers function that throws the message Found an element that is not a number. if one of the elements

Add a throw statement to the processNumbers function that throws the message "Found an element that is not a number." if one of the elements in toProcess is not a number. Hint: The function isNaN() returns true if the parameter is not a number.
function processNumbers(numberList){
let result =0;
for (let index =0; index < numberList.length; index++){
if (isNaN(numberList[index])){
throw new Error("Found an element that is not a number.");
}
result += numberList[index]*1.3* index;
}
return result;
}
Answer above needs corrected as it shows the following error
"Testing if an exception is thrown with toProcess =[1,2,5,7]
Yours and expected differ. See highlights below.
Yours
Yes
Expected
No"
the code below needs fixed
if (isNaN(numberList[index])){
throw Error("Found an element that is not a number.");
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!