From 0d0227633b7bb8d25aa0ca23b2f7aefa962288b6 Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Fri, 24 Feb 2023 21:40:11 +0000 Subject: [PATCH 01/11] fix the error --- mandatory/1-syntax-errors.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index d9e004465..7f4263c93 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,14 +1,14 @@ // There are syntax errors in this code - can you fix it to pass the tests? -function addNumbers(a b c) { +function addNumbers(a, b, c) { return a + b + c; } function introduceMe(name, age) - return `Hello, my {name}` is "and I am $age years old`; + return `Hello, my ${name} is "and I am ${age} years old`; function getTotal(a, b) { - total = a ++ b; + total = a + b; return "The total is total"; } From 2a80686cd7c586e23c6dad8b23570ef86a71c826 Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Fri, 24 Feb 2023 22:12:10 +0000 Subject: [PATCH 02/11] fix the error --- mandatory/2-logic-error.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9eb8c8cd7..717facfdb 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,16 @@ // The syntax for these functions is valid but there are some errors, find them and fix them function trimWord(word) { - return wordtrim(); + return word.trim(); } function getStringLength(word) { - return "word".length(); + return word.length; } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; + } /* From e3848e5edee197989ca057582ec52a5ccb5f2bff Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Fri, 24 Feb 2023 21:40:11 +0000 Subject: [PATCH 03/11] fix the error Revert "fix the error" This reverts commit 0d0227633b7bb8d25aa0ca23b2f7aefa962288b6. From 83bc5c481563204ce6d515de4a22e25d9230d435 Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Fri, 24 Feb 2023 22:12:10 +0000 Subject: [PATCH 04/11] fix the error --- mandatory/2-logic-error.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9eb8c8cd7..717facfdb 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,16 @@ // The syntax for these functions is valid but there are some errors, find them and fix them function trimWord(word) { - return wordtrim(); + return word.trim(); } function getStringLength(word) { - return "word".length(); + return word.length; } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; + } /* From cfc5784f2d7639a9753d1f0c3ffd2fb2f0477a6c Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Fri, 24 Feb 2023 22:22:28 +0000 Subject: [PATCH 05/11] fix mandatory 1 --- mandatory/1-syntax-errors.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index d9e004465..7f4263c93 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,14 +1,14 @@ // There are syntax errors in this code - can you fix it to pass the tests? -function addNumbers(a b c) { +function addNumbers(a, b, c) { return a + b + c; } function introduceMe(name, age) - return `Hello, my {name}` is "and I am $age years old`; + return `Hello, my ${name} is "and I am ${age} years old`; function getTotal(a, b) { - total = a ++ b; + total = a + b; return "The total is total"; } From 305510ce2d8e3e7e2373952953a3a10d5c1f2163 Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Fri, 24 Feb 2023 23:01:41 +0000 Subject: [PATCH 06/11] fix mandatory 3 --- mandatory/3-function-output.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..f3ddfa3a7 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,18 +1,23 @@ // Add comments to explain what this function does. You're meant to use Google! +// we use math.random when we want a random floating point number between 0 and 10. function getRandomNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! +// The concat() method joins two or more strings, in this example there is no space between the words, when we want to put space between words we should put quetation +//example word1.concat(" ", word2); function combine2Words(word1, word2) { return word1.concat(word2); } function concatenate(firstWord, secondWord, thirdWord) { + return firstWord.concat(" ", secondWord, " ", thirdWord); // Write the body of this function to concatenate three words together. // Look at the test case below to understand what this function is expected to return. } + /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== From 091062cab5f869ba98d7f251e952306b810ff551 Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Sat, 25 Feb 2023 00:56:23 +0000 Subject: [PATCH 07/11] fix mandatory4 --- mandatory/4-tax.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..1ace10a86 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,11 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +function calculateSalesTax(price) { + const salesTax = 0.2 * priceOfProduct; + const totalPrice = salesTax + priceOfProduct; + return totalPrice; +} /* CURRENCY FORMATTING @@ -17,7 +21,10 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(price) { + const totalPrice = salesTax + priceOfProduct; + const formatprice = "£" + totalPrice.toFixed(2); +} /* =================================================== From c642de94fe0b524031d1714634abc505b2b1013f Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Sat, 25 Feb 2023 16:25:20 +0000 Subject: [PATCH 08/11] correct the mistakes --- mandatory/1-syntax-errors.js | 9 +++++---- mandatory/4-tax.js | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index 7f4263c93..e6983c6cc 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -4,13 +4,14 @@ function addNumbers(a, b, c) { return a + b + c; } -function introduceMe(name, age) - return `Hello, my ${name} is "and I am ${age} years old`; +function introduceMe(name, age){ + return `Hello, my name is ${name} and I am ${age} years old`;} function getTotal(a, b) { - total = a + b; + const total = a + b; + + return `The total is ${total}`; - return "The total is total"; } /* diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index 1ace10a86..0ba3487cd 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -6,8 +6,8 @@ */ function calculateSalesTax(price) { - const salesTax = 0.2 * priceOfProduct; - const totalPrice = salesTax + priceOfProduct; + const salesTax = 0.2 * price; + const totalPrice = salesTax + price; return totalPrice; } @@ -22,8 +22,9 @@ function calculateSalesTax(price) { */ function addTaxAndFormatCurrency(price) { - const totalPrice = salesTax + priceOfProduct; - const formatprice = "£" + totalPrice.toFixed(2); + const totalPrice = calculateSalesTax(price); + + return "£" + totalPrice.toFixed(2); } /* From d21971983be95a5660206cb69005bfa08b130769 Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Thu, 2 Mar 2023 13:00:04 +0000 Subject: [PATCH 09/11] extra 1 , 2 --- extra/1-currency-conversion.js | 13 +++++++++++-- extra/2-piping.js | 19 +++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 75b3c6aab..bdeda8228 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,7 +5,12 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(Pound) { + let USD= Pound * 1.4; + return USD; + + +} /* CURRENCY CONVERSION @@ -14,8 +19,12 @@ function convertToUSD() {} Write a new function for converting to the Brazilian real (exchange rate is 5.7 BRL to £) They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL. */ +function convertToBrl(amountInpound){ + + const amountInBRL= 0.99 * amountInpound * 5.7; + return Number(amountInBRL.toFixed(2)); + } -function convertToBRL() {} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. diff --git a/extra/2-piping.js b/extra/2-piping.js index b4f8c4c1b..3e9841b36 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -16,26 +16,33 @@ the final result to the variable goodCode */ -function add() { +function addNumbers(num1, num2) { + return num1+num2; } -function multiply() { - +function multiplynumbers(num1, num2) { +return num1*num2; } -function format() { +function formatasapound(amount) { + return "£" + amount; } const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = +let badCode = formatasapound(multiplynumbers(addNumbers(startingValue,10),2)); + /* BETTER PRACTICE */ +const valueAfterAddition = addNumbers(startingValue,10); // 12 +const valueAfterMultiplication = multiplynumbers(valueAfterAddition,2); //12*2 +const formattedValue = Formatasapound(valueAfterMultiplication); +let goodcode = formattedValue; +console.log(goodcode); -let goodCode = /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. From 6d594618c5e0c13e635c65f77847b60bf1cf5e5b Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Thu, 2 Mar 2023 13:44:11 +0000 Subject: [PATCH 10/11] fix extra 1 --- extra/1-currency-conversion.js | 13 +++++++------ extra/2-piping.js | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index bdeda8228..7e562cdb0 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,9 +5,9 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD(Pound) { - let USD= Pound * 1.4; - return USD; +function convertToUSD(price) { + return price * 1.4; + } @@ -19,10 +19,11 @@ function convertToUSD(Pound) { Write a new function for converting to the Brazilian real (exchange rate is 5.7 BRL to £) They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL. */ -function convertToBrl(amountInpound){ +function convertToBRL(price){ - const amountInBRL= 0.99 * amountInpound * 5.7; - return Number(amountInBRL.toFixed(2)); + let priceAfterFee = price * 0.99; + let priceInBRL = priceAfterFee * 5.7; + return Math.round(priceInBRL * 100) / 100; } diff --git a/extra/2-piping.js b/extra/2-piping.js index 3e9841b36..9c0d34fa9 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -16,16 +16,16 @@ the final result to the variable goodCode */ -function addNumbers(num1, num2) { - return num1+num2; +function add(num1, num2) { // + return num1 + num2; } -function multiplynumbers(num1, num2) { -return num1*num2; +function multiply(num1, num2) { +return num1 * num2; } -function formatasapound(amount) { +function format(amount) { return "£" + amount; } @@ -33,15 +33,15 @@ function formatasapound(amount) { const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = formatasapound(multiplynumbers(addNumbers(startingValue,10),2)); +let badCode = format(multiply(add(startingValue, 10), 2)); /* BETTER PRACTICE */ -const valueAfterAddition = addNumbers(startingValue,10); // 12 -const valueAfterMultiplication = multiplynumbers(valueAfterAddition,2); //12*2 -const formattedValue = Formatasapound(valueAfterMultiplication); -let goodcode = formattedValue; -console.log(goodcode); +const valueAfterAddition = add(startingValue, 10); // 12 +const valueAfterMultiplication = multiply(valueAfterAddition, 2); //12*2 +// const formattedValue = formatasapound(valueAfterMultiplication); +let goodcode = format(valueAfterMultiplication); +// console.log(goodcode); /* ======= TESTS - DO NOT MODIFY ===== From 4315ed4164ec45d1f43a141705e949805ff748fa Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Sat, 4 Mar 2023 11:17:58 +0000 Subject: [PATCH 11/11] FIX extra/2 --- extra/2-piping.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/extra/2-piping.js b/extra/2-piping.js index 9c0d34fa9..e13bdfaed 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -30,18 +30,18 @@ function format(amount) { } -const startingValue = 2; +let startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. let badCode = format(multiply(add(startingValue, 10), 2)); /* BETTER PRACTICE */ -const valueAfterAddition = add(startingValue, 10); // 12 -const valueAfterMultiplication = multiply(valueAfterAddition, 2); //12*2 -// const formattedValue = formatasapound(valueAfterMultiplication); -let goodcode = format(valueAfterMultiplication); -// console.log(goodcode); +let valueAfterAddition = add(startingValue, 10); // 12 +let valueAfterMultiplication = multiply(valueAfterAddition, 2); //12*2 + +let goodCode = format(valueAfterMultiplication); + /* ======= TESTS - DO NOT MODIFY =====