From 9cf45cb457dff62fd7d86842e56ad9f52012f1cc Mon Sep 17 00:00:00 2001 From: ggesm <117891063+ggesm@users.noreply.github.com> Date: Wed, 30 Apr 2025 01:35:56 -0700 Subject: [PATCH 1/8] Update lab4.js Fixed buggy code in scripts folder --- scripts/lab4.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/lab4.js b/scripts/lab4.js index ce452ba..25ee508 100644 --- a/scripts/lab4.js +++ b/scripts/lab4.js @@ -7,14 +7,14 @@ */ function sumValues(num1, num2, add) { if (add) { - const result = 0; + let result = 0; result = num1 + num2; return result; } else { - return !add; + return false; } } @@ -29,11 +29,11 @@ function discountPrices(prices, discount) { const length = prices.length; let discountedPrice = 0 for(let i = 0; i < length; i++) { - discountedPrice += prices[i] * (1 - discount); + let discountedPrice += prices[i] * (1 - discount); discounted.push(discountedPrice); } return discounted; } -module.exports = {sumValues, discountPrices}; \ No newline at end of file +module.exports = {sumValues, discountPrices}; From a0487e02e3598191f2eadd9fe2a9d640c2b6a462 Mon Sep 17 00:00:00 2001 From: ggesm <117891063+ggesm@users.noreply.github.com> Date: Wed, 30 Apr 2025 01:41:20 -0700 Subject: [PATCH 2/8] Update lab4.js Fixed buggy code in the scripts folder --- scripts/lab4.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lab4.js b/scripts/lab4.js index 25ee508..58c5efd 100644 --- a/scripts/lab4.js +++ b/scripts/lab4.js @@ -29,7 +29,7 @@ function discountPrices(prices, discount) { const length = prices.length; let discountedPrice = 0 for(let i = 0; i < length; i++) { - let discountedPrice += prices[i] * (1 - discount); + let discountedPrice = prices[i] * (1 - discount); discounted.push(discountedPrice); } From 6f955c8cdc8cbab9b6db66da62090ee809cb9881 Mon Sep 17 00:00:00 2001 From: ggesm <117891063+ggesm@users.noreply.github.com> Date: Wed, 30 Apr 2025 01:48:53 -0700 Subject: [PATCH 3/8] Update lab4.js Fixing the rest of the bugs for the scripts file --- scripts/lab4.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/lab4.js b/scripts/lab4.js index 58c5efd..1ee3530 100644 --- a/scripts/lab4.js +++ b/scripts/lab4.js @@ -6,7 +6,7 @@ * @returns The sum of the two numbers if add is true and false otherwise. */ function sumValues(num1, num2, add) { - if (add) { + if (add && typeof num === 'number' && typeof num2 === 'number') { let result = 0; result = num1 + num2; @@ -25,7 +25,9 @@ function sumValues(num1, num2, add) { * @returns An array of each price's new price, after the discount is applied. Or false, if prices array is empty. */ function discountPrices(prices, discount) { - const discounted = [] + if (prices.length === 0) return false; + + let discounted = [] const length = prices.length; let discountedPrice = 0 for(let i = 0; i < length; i++) { From cb5a9c6b4f2b02de7b8b858d21f8de03998954a4 Mon Sep 17 00:00:00 2001 From: ggesm <117891063+ggesm@users.noreply.github.com> Date: Wed, 30 Apr 2025 01:51:46 -0700 Subject: [PATCH 4/8] Update lab4.js Fixed more bugs in scripts file --- scripts/lab4.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/lab4.js b/scripts/lab4.js index 1ee3530..07944f3 100644 --- a/scripts/lab4.js +++ b/scripts/lab4.js @@ -25,7 +25,9 @@ function sumValues(num1, num2, add) { * @returns An array of each price's new price, after the discount is applied. Or false, if prices array is empty. */ function discountPrices(prices, discount) { - if (prices.length === 0) return false; + if (!Array.isArray(prices) || prices.length === 0 || typeof discount !== 'number' || discount < 0 || discount > 1) { + return false; + } let discounted = [] const length = prices.length; From 8c10e378c9845df632883537eb573e0cb1bdfec0 Mon Sep 17 00:00:00 2001 From: ggesm <117891063+ggesm@users.noreply.github.com> Date: Wed, 30 Apr 2025 01:55:22 -0700 Subject: [PATCH 5/8] Update lab4.js Fixed bugs in scripts file --- scripts/lab4.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/lab4.js b/scripts/lab4.js index 07944f3..ea022e8 100644 --- a/scripts/lab4.js +++ b/scripts/lab4.js @@ -6,7 +6,7 @@ * @returns The sum of the two numbers if add is true and false otherwise. */ function sumValues(num1, num2, add) { - if (add && typeof num === 'number' && typeof num2 === 'number') { + if (typeof num1 !== 'number' || typeof num2 !== 'number') { let result = 0; result = num1 + num2; @@ -29,10 +29,10 @@ function discountPrices(prices, discount) { return false; } - let discounted = [] + const discounted = [] const length = prices.length; let discountedPrice = 0 - for(let i = 0; i < length; i++) { + for (let i = 0; i < length; i++) { let discountedPrice = prices[i] * (1 - discount); discounted.push(discountedPrice); } From fc91610a7e7c0fdf6d851b733b51ef3d883c9dd7 Mon Sep 17 00:00:00 2001 From: ggesm <117891063+ggesm@users.noreply.github.com> Date: Wed, 30 Apr 2025 01:59:14 -0700 Subject: [PATCH 6/8] Update lab4.js Fixed bugs in scripts file --- scripts/lab4.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/lab4.js b/scripts/lab4.js index ea022e8..ba243f3 100644 --- a/scripts/lab4.js +++ b/scripts/lab4.js @@ -6,7 +6,7 @@ * @returns The sum of the two numbers if add is true and false otherwise. */ function sumValues(num1, num2, add) { - if (typeof num1 !== 'number' || typeof num2 !== 'number') { + if (add) { let result = 0; result = num1 + num2; @@ -25,14 +25,11 @@ function sumValues(num1, num2, add) { * @returns An array of each price's new price, after the discount is applied. Or false, if prices array is empty. */ function discountPrices(prices, discount) { - if (!Array.isArray(prices) || prices.length === 0 || typeof discount !== 'number' || discount < 0 || discount > 1) { - return false; - } + if (prices.length === 0) return false; const discounted = [] - const length = prices.length; let discountedPrice = 0 - for (let i = 0; i < length; i++) { + for (let i = 0; i < prices.length; i++) { let discountedPrice = prices[i] * (1 - discount); discounted.push(discountedPrice); } From f43e34b876c60dc69ff81d062e5b3fa14629e5c5 Mon Sep 17 00:00:00 2001 From: ggesm <117891063+ggesm@users.noreply.github.com> Date: Wed, 30 Apr 2025 02:03:54 -0700 Subject: [PATCH 7/8] Update lab4.js Fixed bugs in scripts file --- scripts/lab4.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lab4.js b/scripts/lab4.js index ba243f3..55b5df6 100644 --- a/scripts/lab4.js +++ b/scripts/lab4.js @@ -6,7 +6,7 @@ * @returns The sum of the two numbers if add is true and false otherwise. */ function sumValues(num1, num2, add) { - if (add) { + if (add === true) { let result = 0; result = num1 + num2; From 3cf2592b4ecc4d75a9c90ac9ef40d2fe95e08066 Mon Sep 17 00:00:00 2001 From: ggesm <117891063+ggesm@users.noreply.github.com> Date: Wed, 30 Apr 2025 02:07:24 -0700 Subject: [PATCH 8/8] Update lab4.js fixed more bugs in scripts file --- scripts/lab4.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/lab4.js b/scripts/lab4.js index 55b5df6..1111d99 100644 --- a/scripts/lab4.js +++ b/scripts/lab4.js @@ -6,8 +6,10 @@ * @returns The sum of the two numbers if add is true and false otherwise. */ function sumValues(num1, num2, add) { - if (add === true) { - let result = 0; + if (add === true) { + if (typeof num1 !== 'number' || typeof num2 !== 'number') { + return false; + } result = num1 + num2; @@ -25,6 +27,9 @@ function sumValues(num1, num2, add) { * @returns An array of each price's new price, after the discount is applied. Or false, if prices array is empty. */ function discountPrices(prices, discount) { + if (!Array.isArray(prices) || typeof discount !== 'number') { + return false; + } if (prices.length === 0) return false; const discounted = []