From 628b60ec3e841c00b5c87bef744de1f906566180 Mon Sep 17 00:00:00 2001 From: lalehkoupa Date: Mon, 13 Dec 2021 13:25:44 +0000 Subject: [PATCH 1/2] londonclass8 -Laleh Koupaei-JavaScript-Week1 --- .DS_Store | Bin 0 -> 6148 bytes exercises/B-hello-world/README.md | 3 +++ exercises/B-hello-world/exercise.js | 3 +++ exercises/C-variables/exercise.js | 4 ++- exercises/D-strings/exercise.js | 4 ++- exercises/E-strings-concatenation/exercise.js | 5 ++-- exercises/F-strings-methods/exercise.js | 5 +++- exercises/F-strings-methods/exercise2.js | 15 +++++++++-- exercises/G-numbers/exercise.js | 6 +++++ exercises/I-floats/exercise.js | 13 +++++++-- exercises/J-functions/exercise.js | 10 +++++-- exercises/J-functions/exercise2.js | 2 +- exercises/K-functions-parameters/exercise.js | 6 ++--- exercises/K-functions-parameters/exercise2.js | 3 +++ exercises/K-functions-parameters/exercise3.js | 4 ++- exercises/K-functions-parameters/exercise4.js | 5 +++- exercises/K-functions-parameters/exercise5.js | 4 ++- exercises/L-functions-nested/exercise.js | 11 ++++++++ extra/1-currency-conversion.js | 16 ++++++++--- extra/2-piping.js | 22 ++++++++++----- extra/3-magic-8-ball.js | 25 +++--------------- mandatory/1-syntax-errors.js | 12 +++++---- mandatory/2-logic-error.js | 8 +++--- mandatory/3-function-output.js | 7 +++++ mandatory/4-tax.js | 12 +++++++-- package.json | 14 +++++++--- 26 files changed, 154 insertions(+), 65 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8bae2d56ef66a09249f3bebedb02e19d175515ab GIT binary patch literal 6148 zcmeHK%Wl&^6upzAG)YSd2&8V1EU`^OT17~RO%f781qDrA~Jq6!fekpvdX$TCdyi*(L% zy5$;>i5Pt72HZtWgfnIoFbe$b3W&X%ry)fY?FFg*+s3Be`Xx59ZZa(B;?D*kmA_=}X zg3FsjKlJ#l!>6GaNv^FrO0Yp?dp_T3HmlZdv$3dJ^ZUDvs@1<r5h(TX*h0I2fD+ zry>8WL}&OWNxQ1?48EYCXY;|HgaHqa&?3A`G@_446DZL-uV0@w^V-wz7jxqpOl%^D9teseqB=0(nG18DukRQRn1{Rm~I=#p0 za|+WV%k@b{*j$Nl5l`rnZP0BAH|JJk8A=O1&jj!x&q?+ zU?B-?XAM3{bo95h|5Bl% z6O$t&jvkrm8w%4`4`xYsVl9OxHwqX9(hB5NwIa^{-o^L-G|AMA0!D%VN&!~r+T9MO zq|erKlM`pHh4c { ); } - let seenPositivities = new Set(Array.from(seenAnswers.values()).map(checkAnswer)); + let seenPositivities = new Set( + Array.from(seenAnswers.values()).map(checkAnswer) + ); if (seenPositivities.size < 2) { throw Error( "Expected to random answers with different positivities each time shakeBall was called, but always got the same one" diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..cfd19b968 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,16 +1,18 @@ // 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 " + name "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; + 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..4902e77f2 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,16 @@ // 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..dc0265de1 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -2,15 +2,22 @@ function getRandomNumber() { return Math.random() * 10; } +/********************************************************************************** */ +/*Math.random() returns a random number between 0 (inclusive), and 1 (exclusive) +/********************************************************************************** */ // Add comments to explain what this function does. You're meant to use Google! function combine2Words(word1, word2) { return word1.concat(word2); } +/********************************************************************************** */ +/*The concat() method joins two or more strings +/********************************************************************************** */ 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)+" ".concat(thirdWord); } /* diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..e8b91c384 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(itemPrice) { + let tax = itemPrice * 0.2; + let total=tax+itemPrice; + return total; +} /* CURRENCY FORMATTING @@ -17,7 +21,11 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(itemPrice) { + let totalPrice = calculateSalesTax(itemPrice); + let formatPrice = "£" + totalPrice.toFixed(2); + return formatPrice; +} /* =================================================== diff --git a/package.json b/package.json index 93e0861e3..ff48de45a 100644 --- a/package.json +++ b/package.json @@ -14,21 +14,27 @@ "url": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/issues" }, "jest": { - "setupFilesAfterEnv": ["jest-extended"], + "setupFilesAfterEnv": [ + "jest-extended" + ], "projects": [ { "displayName": "mandatory", - "testMatch": ["/mandatory/*.js"] + "testMatch": [ + "/mandatory/*.js" + ] }, { "displayName": "extra", - "testMatch": ["/extra/*.js"] + "testMatch": [ + "/extra/*.js" + ] } ] }, "homepage": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1#readme", "devDependencies": { "jest": "^26.6.3", - "jest-extended": "^0.11.5" + "jest-extended": "^1.2.0" } } From 723de7647ad65e1f865fd0be4eb82f701da04fe9 Mon Sep 17 00:00:00 2001 From: lalehkoupa Date: Tue, 14 Dec 2021 10:20:10 +0000 Subject: [PATCH 2/2] Update 1-currency-conversion.js --- extra/1-currency-conversion.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index dbad993da..2ebfd1daf 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -22,7 +22,7 @@ function convertToUSD(priceInPound) { function convertToBRL(priceInPound) { let priceInBrazilian = 0.99 * priceInPound * 5.7; - return priceInBrazilian.toFixed(2); + return Number(priceInBrazilian.toFixed(2)); } /* ======= TESTS - DO NOT MODIFY =====