From 5b836e03ae5186eb55dd41fe9e47ebd6d7979e00 Mon Sep 17 00:00:00 2001 From: Hussein Date: Wed, 1 Mar 2023 18:31:56 +0000 Subject: [PATCH 1/4] 1st file functions fixed --- mandatory/1-fix-functions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mandatory/1-fix-functions.js b/mandatory/1-fix-functions.js index 6323604f..c9bb6e9b 100644 --- a/mandatory/1-fix-functions.js +++ b/mandatory/1-fix-functions.js @@ -10,7 +10,7 @@ */ -function getMood() { +function getMood(isHappy) { let isHappy = true; if (isHappy) { @@ -21,7 +21,7 @@ function getMood() { } function greaterThan10(num) { - let isBigEnough; + let isBigEnough = Number > 10; if (isBigEnough) { return "num is greater than 10"; From cfe1a2e22bcc2b9681b2237815f370f03b2ccafb Mon Sep 17 00:00:00 2001 From: Hussein Date: Wed, 1 Mar 2023 21:40:35 +0000 Subject: [PATCH 2/4] 2nd file functions completed --- mandatory/2-function-creation.js | 50 ++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/mandatory/2-function-creation.js b/mandatory/2-function-creation.js index d4590920..0e473b8c 100644 --- a/mandatory/2-function-creation.js +++ b/mandatory/2-function-creation.js @@ -4,7 +4,9 @@ 1. the user should be 18 or older 2. the user must be logged in */ -function isAcceptableUser(userAge, isLoggedIn) {} +function isAcceptableUser(userAge, isLoggedIn) { + return userAge >= 18 && isLoggedIn; +} /* Complete the function to apply discount percent based on how much is totalPrice in user cart. @@ -15,18 +17,40 @@ function isAcceptableUser(userAge, isLoggedIn) {} is applieds and 142.5 should be returned) */ -function applyDiscount(totalPrice) {} +function applyDiscount(totalPrice) { + if (totalPrice > 200) { +return totalPrice * 0.9; +} else { +return totalPrice * 0.95; +}; +} /* Complete the function to print to the console the odd numbers between 1 and limit (use a while loop): */ -function printOddNumbers(limit) {} +function printOddNumbers(limit) { + let number = 1; +while (number <= limit) { +if (number % 2 == 1) { +console.log(number); +} +number++; +}; +} /* Complete the buyTwoGetTheCheapestFree function: if user buys two items, the cheapest item will be free! The function should return the price to be paid once the discount is applied. */ -function buyTwoGetTheCheapestFree(price1, price2) {} +function buyTwoGetTheCheapestFree(price1, price2) { + if (price1 > price2) { +return price1; +} else if (price2 > price1) { +return price2; +} else { + return price1||price2; +}; +} /* Complete the function to determine if it is suitable for a person to register based on their age! @@ -34,7 +58,15 @@ function buyTwoGetTheCheapestFree(price1, price2) {} - if the person is older than 12 and younger than 90 it should return "You Can Register" - if the person is 90 or older it should return "You Don't Need To Register" */ -function canRegister(age) {} +function canRegister(age) { + if (age < 13) { +return "You Are Too Young To Register"; +} else if (age < 90) { +return "You Can Register"; +} else { +return "You Don't Need To Register"; +}; +} /* Complete the function so that it prints out to the console numbers in reverse order starting at @@ -45,7 +77,13 @@ function canRegister(age) {} ) */ -function countReverse(number) {} +function countReverse(number) { + + while (number > 0) { + console.log(number); + number--; + }; +} /* ======= TESTS - DO NOT MODIFY ===== */ From b55654e38443fdf8b82145c0b943ee0373ff51b3 Mon Sep 17 00:00:00 2001 From: Hussein Date: Fri, 3 Mar 2023 22:12:40 +0000 Subject: [PATCH 3/4] tests runned successful --- mandatory/1-fix-functions.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mandatory/1-fix-functions.js b/mandatory/1-fix-functions.js index c9bb6e9b..2fa5fc4c 100644 --- a/mandatory/1-fix-functions.js +++ b/mandatory/1-fix-functions.js @@ -11,7 +11,6 @@ */ function getMood(isHappy) { - let isHappy = true; if (isHappy) { return "I am happy"; @@ -21,7 +20,7 @@ function getMood(isHappy) { } function greaterThan10(num) { - let isBigEnough = Number > 10; + let isBigEnough = num > 10; if (isBigEnough) { return "num is greater than 10"; From d9f41e85678afb3201b458f1b4d3d9a5f347dc16 Mon Sep 17 00:00:00 2001 From: Hussein Date: Fri, 3 Mar 2023 23:14:19 +0000 Subject: [PATCH 4/4] few issues fixed upon github comments --- mandatory/2-function-creation.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mandatory/2-function-creation.js b/mandatory/2-function-creation.js index 0e473b8c..16e8c9f1 100644 --- a/mandatory/2-function-creation.js +++ b/mandatory/2-function-creation.js @@ -19,10 +19,10 @@ function isAcceptableUser(userAge, isLoggedIn) { function applyDiscount(totalPrice) { if (totalPrice > 200) { -return totalPrice * 0.9; -} else { -return totalPrice * 0.95; -}; + return totalPrice * 0.9; + } else { + return totalPrice * 0.95; + }; } /* @@ -48,7 +48,7 @@ return price1; } else if (price2 > price1) { return price2; } else { - return price1||price2; + return price1; }; } @@ -59,7 +59,7 @@ return price2; - if the person is 90 or older it should return "You Don't Need To Register" */ function canRegister(age) { - if (age < 13) { + if (age <= 12) { return "You Are Too Young To Register"; } else if (age < 90) { return "You Can Register";