here what need to be done Implement a function addWithDelay() which will work with parameters according to the conditions below:
- If all parameters are positive numbers, it should return within 1000ms timeframe a Promise containing a sum of all the numbers provided as parameters .
- If any parameter is represented by a negative number, function should return an error message: “Error! Some parameter is a negative number!" using “reject()” option. Here my code
function addWithDelay(
param1 = 633,
param2 = 345,
param3 = 986,
param4 = 234,
param5 = 532,
){
values = [param1, param2, param3, param4, param5];
var result = values.filter(function(number) {
return number < 0;
});
if (number > 0){
return Promise.resolve((param1+param2+param3+param4+param5),1000)
} else {
return Promise.reject('Error! Some parameter is a negative number!')
}
}
console.log(addWithDelay())
for some reason it always returned an error message