Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
580 B
2
Indexable
Never
function monthlySavings(arr, livingCost) {
  if (Array.isArray(arr) && typeof livingCost === "number") {
    let taxMoney = 0;
    for (let product of arr) {
      if (product >= 3000) {
        taxMoney += product * 0.8;
      } else {
        taxMoney += product;
      }
    }
    if (taxMoney > livingCost) {
      const Savings = taxMoney - livingCost;
      return Savings;
    } else {
      return "earn more";
    }
  } else {
    return "Invalid Input";
  }
}
const checkMoney = monthlySavings(10000, [(900, 2700, 3400)]);
console.log(checkMoney);
Leave a Comment