From f25dfde1ca167d07c3bfc32a6cc4d1c932ed0598 Mon Sep 17 00:00:00 2001 From: SagharHosseinmardi Date: Wed, 23 Nov 2022 21:03:47 +0000 Subject: [PATCH 1/4] exercises --- .DS_Store | Bin 0 -> 6148 bytes exercises/.DS_Store | Bin 0 -> 6148 bytes exercises/B-hello-world/exercise.js | 1 + exercises/C-variables/exercise.js | 4 +++- exercises/D-strings/exercise.js | 6 ++++-- exercises/E-strings-concatenation/exercise.js | 5 ++++- exercises/F-strings-methods/exercise.js | 10 +++++++-- exercises/F-strings-methods/exercise2.js | 7 +++++- exercises/G-numbers/exercise.js | 8 ++++++- exercises/I-floats/exercise.js | 5 +++++ exercises/J-functions/exercise.js | 2 +- exercises/J-functions/exercise2.js | 2 +- exercises/K-functions-parameters/exercise.js | 4 ++-- exercises/K-functions-parameters/exercise2.js | 5 ++++- exercises/K-functions-parameters/exercise3.js | 4 +++- exercises/K-functions-parameters/exercise4.js | 5 ++++- exercises/K-functions-parameters/exercise5.js | 3 +++ exercises/L-functions-nested/exercise.js | 20 ++++++++++++++++++ 18 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 .DS_Store create mode 100644 exercises/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2404ad5a7ba09f1d9d9bb7e234998d5e82f3d940 GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8CWx4WV2`mijY^dN*-58i}`9#q=I78|HZNm8T6NM1wV$S3f1 zoY~zLOY6mhNSP_K-|YPCvfq~7EMts2lYWyigE6LoB35*0mI%gC7o?&*h+K?u%L10L z0ZaUBA)6fkkpbL09d_&yG-luSFB$uz$cN~MKOO~1YFVGWQmw76Z)iIFwzL~}7-eqi zrIW<*;w$W(dFjws_IVVIX13>F1cR(=>>Nj7>ILB-7R5n-04dj(LD-KnCz^!)M2zFg z0M4U#je4FRSnY<{YBr08nYZ^Xun${Bp=-N)&7;%a{nK;)QoO!NemVRVg={OF!aEpC zmipkv;V264AUds_RuB>c!~ij{q710xPTO43_0h730b=0y4B+`-f+E@qONrv>fCfJw zFCqKXc=ZmOE3=jh=#Q?8$+>QfFQg`dZ;_$9DL3^Mmm{&@i lm4G3xV#vj-xDF}={3aTJw!%^(ctGewK+r%9G4Q7hd;!osQ@Q{E literal 0 HcmV?d00001 diff --git a/exercises/.DS_Store b/exercises/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..93f46191e1eb468c033aa74fb753d208772f3200 GIT binary patch literal 6148 zcmeHK!AiqG5Z!I7CP=Xd!5(w*R-vt>=s^gv9=r(=J*cz^DK-$ZrA-YQEBOumBfr4k zab|a0DOFD*SZ2!Xo86t+W!{#ZEMts2lc2#^g)wG;A{I<&z7U*8U6O(xLF96ch(%1W zJ(faC@*fz$vnw+P&TPQ?aC)ETHv&8G)A7)cgb!YC{xAy1NxlBg3&qmf`i5b`uWa17 z1ChFkmrTZvH@d>!nU@TFZJ!Gf&27)W2>WTbvVAP##0%s8NCt;NA6%|4!#EJBBPMY$ zmg~4`0{1bym1>qX+x42YUq6`Etn9D}cB|c*PEBKHw{djZyL))do~F+)igylwNhw&@6)k$fl(Vt^RITA)2p q6!gm#&O^YEr5Jp%6jwo|z_^75psg`i2qPf$As}g>h8Xx$20j2l_f Date: Wed, 23 Nov 2022 22:06:11 +0000 Subject: [PATCH 2/4] Update 1-syntax-errors.js --- mandatory/1-syntax-errors.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..2140e0f80 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,14 +1,15 @@ // 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; } +addNumbers(3, 4, 6) function introduceMe(name, age) - return "Hello, my name is " + name "and I am " age + "years old"; + return "Hello, my name is " + name + "and I am " + age + " years old"; function getTotal(a, b) { - total = a ++ b; + total = a + b; return "The total is total"; } From 78c5f8468d6ff4e2d86db193f4a1c296a2dc6969 Mon Sep 17 00:00:00 2001 From: SagharHosseinmardi Date: Fri, 25 Nov 2022 12:54:46 +0000 Subject: [PATCH 3/4] Mandatory --- mandatory/1-syntax-errors.js | 12 ++++++------ mandatory/2-logic-error.js | 7 +++---- mandatory/3-function-output.js | 3 +++ mandatory/4-tax.js | 12 +++++++++--- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index 2140e0f80..7561cf3fb 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -3,15 +3,15 @@ function addNumbers(a, b, c) { return a + b + c; } -addNumbers(3, 4, 6) - -function introduceMe(name, age) - return "Hello, my name is " + name + "and I am " + age + " years old"; +addNumbers(3, 4, 6); +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/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..37c4ebc15 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,15 @@ // The syntax for this function is valid but it has an error, find it and fix it. 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; } /* diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..eebf4abca 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,9 +1,11 @@ // Add comments to explain what this function does. You're meant to use Google! +// Math.random() returns a random number between 0 (inclusive), and 1 (exclusive) function getRandomNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! +// The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array. function combine2Words(word1, word2) { return word1.concat(word2); } @@ -11,6 +13,7 @@ function combine2Words(word1, word2) { function concatenate(firstWord, 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. + return firstWord.concat(" ", secondWord, " ", thirdWord); } /* diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..9eef658fb 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) { + return price * 1.2; +} + +// let totalWithTax = calculateSalesTax(); /* CURRENCY FORMATTING @@ -17,10 +21,12 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(price) { + return "£" + calculateSalesTax(price).toFixed(2); +} /* -=================================================== +====================`=============================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== There are some Tests in this file that will help you work out if your code is working. From b5f77dcad564f40b107a7fda73d734277dae887a Mon Sep 17 00:00:00 2001 From: SagharHosseinmardi Date: Fri, 25 Nov 2022 16:19:41 +0000 Subject: [PATCH 4/4] extra --- extra/1-currency-conversion.js | 11 +++++++++-- extra/2-piping.js | 21 ++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 75b3c6aab..07a9892b0 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,7 +5,9 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(price) { + return price * 1.4; +} /* CURRENCY CONVERSION @@ -15,7 +17,12 @@ function convertToUSD() {} 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() {} +function convertToBRL(price) { + let newPrice = (99 * price) / 100; + let convertedPrice = newPrice * 5.7; + let inStringPrice = convertedPrice.toFixed(2); + return parseFloat(inStringPrice); +} /* ======= 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..f7b9c4547 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -16,26 +16,29 @@ the final result to the variable goodCode */ -function add() { - +function add(numberOne, numberTwo) { + return numberOne + numberTwo; } -function multiply() { - +function multiply(numberOne, numberTwo) { + return numberOne * numberTwo; } -function format() { - +function format(formattedPrice) { + return "£" + formattedPrice; } const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = +// It is not clear and very confusing. +let badCode = format(multiply(add(startingValue, 10), 2)); /* BETTER PRACTICE */ - -let goodCode = +let addingNumber = add(startingValue, 10); +let multiplyingNumber = multiply(addingNumber, 2); +let formattingNumber = format(multiplyingNumber); +let goodCode = formattingNumber; /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working.