From 8e7f3fd65956b72907e570b871169b75b1cd81ac Mon Sep 17 00:00:00 2001 From: ChristinaMifsud Date: Thu, 16 Feb 2023 22:02:52 +0000 Subject: [PATCH 1/7] Homework Attempt --- mandatory/1-syntax-errors.js | 24 ++++++++++++------ mandatory/2-logic-error.js | 44 ++++++++++++++++++++++++++------ mandatory/3-function-output.js | 29 +++++++++++++++++++++ mandatory/4-tax.js | 46 ++++++++++++++++++++++++++++++++-- package.json | 12 ++++++--- 5 files changed, 135 insertions(+), 20 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index d9e004465..bdc22dc11 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,17 +1,27 @@ // There are syntax errors in this code - can you fix it to pass the tests? +let x = 3; +let y = 4; +let z = 6; +function addNumbers(x, y, z) { + return x + y + z; +} +console.log(addNumbers); + -function addNumbers(a b c) { - return a + b + c; +let name = "Sonjide"; +let age = 27; +function introduceMe(name, age){ + return `Hello, my name is ${name} and I am ${age} years old`; } +console.log(introduceMe); -function introduceMe(name, age) - return `Hello, my {name}` is "and I am $age years old`; +let a = 23; +let b = 5; function getTotal(a, b) { - total = a ++ b; - - return "The total is total"; + return `The total is ${total = a + b}`; } +console.log(getTotal); /* =================================================== diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9eb8c8cd7..416a63947 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,17 +1,47 @@ // The syntax for these functions is valid but there are some errors, find them and fix them +/* +let word =" CodeYourFuture "; +function trimWord(word) { + return word.trim(); +} +*/ +let word = " CodeYourFuture teaches coding "; +let result= word.replace (' '); function trimWord(word) { - return wordtrim(); + return word.trim(); +} + +/* +function getStringLength() { + let text = "Turtles"; + return text.length; } +*/ -function getStringLength(word) { - return "word".length(); +function getStringLength() { + let phrase = "A wild sentence appeared!"; + return phrase.length; } + +/* +let a = 2; +let b = 3; +let c = 4; function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; +} +console.log(multiply); +*/ + +let x = 2; +let y = 3; +let z = 6; +function multiply(x, y, z) { + return x * y * z; } +console.log(multiply); /* =================================================== @@ -29,9 +59,7 @@ test("trimWord trims leading and trailing whitespace", () => { }); test("trimWord doesn't remove whitespace in the middle of the string", () => { - expect(trimWord(" CodeYourFuture teaches coding ")).toEqual( - "CodeYourFuture teaches coding" - ); + expect(trimWord(" CodeYourFuture teaches coding ")).toEqual("CodeYourFuture teaches coding"); }); test("getStringLength returns the length of a word", () => { diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..f48ac4cbc 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -2,16 +2,45 @@ function getRandomNumber() { return Math.random() * 10; } +/* Generates a random number. As the values generated are between 0 and 1 we need to multiply by 10 to get a whole number between 1 and 10. */ + // 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 concatenates (joins) two or more strings. It returns a new array, containing the joined strings. */ +/* +let firstWord = "code"; +let secondWord = "your"; +let thirdWord = "future"; 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); +} +console.log(concatenate); +*/ +/* +let firstWord = "I"; +let secondWord = "like"; +let thirdWord = "pizza"; +function concatenate(firstWord, secondWord, thirdWord) { +return firstWord.concat(" ", secondWord, " ", thirdWord); +} +console.log(concatenate); +*/ + +let firstWord = "I"; +let secondWord = "am"; +let thirdWord = 13; +function concatenate(firstWord, secondWord, thirdWord) { +return firstWord.concat(" ", secondWord, " ", thirdWord); } +console.log(concatenate); + + /* =================================================== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..b975513e7 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -4,8 +4,26 @@ A business requires a program that calculates how much the price of a product is including sales tax Sales tax is 20% of the price of the product. */ + -function calculateSalesTax() {} +function calculateSalesTax() { + let product = 15; + let salesTax = (product * 20) / 100; + return priceTotal = product + salesTax; +} +/* +function calculateSalesTax() { + let product = 17.50; + let salesTax = (product * 20) / 100; + return priceTotal = product + salesTax; +} + +function calculateSalesTax() { + let product = 34; + let salesTax = (product * 20) / 100; + return priceTotal = product + salesTax; +} +*/ /* CURRENCY FORMATTING @@ -16,8 +34,32 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ +/* +function addTaxAndFormatCurrency() { + let product = 15; + let salesTax = (product * 20) / 100; + let priceTotal = product + salesTax + + return `£${priceTotal.toFixed(2)}`; +} +*/ +/* +function addTaxAndFormatCurrency() { + let product = 17.50; + let salesTax = (product * 20) / 100; + let priceTotal = product + salesTax + + return `£${priceTotal.toFixed(2)}`; +} +*/ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency() { + let product = 34; + let salesTax = (product * 20) / 100; + let priceTotal = product + salesTax + + return `£${priceTotal.toFixed(2)}`; +} /* =================================================== diff --git a/package.json b/package.json index 93e0861e3..9e7f2ffeb 100644 --- a/package.json +++ b/package.json @@ -14,15 +14,21 @@ "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" + ] } ] }, From 16a63adf66ab6b819b5c6da69a56cf773f31986b Mon Sep 17 00:00:00 2001 From: ChristinaMifsud <102205880+christina-mifsud@users.noreply.github.com> Date: Sat, 18 Feb 2023 11:12:52 +0000 Subject: [PATCH 2/7] Update mandatory/1-syntax-errors.js Co-authored-by: Maksim Lukianenko <93668989+Mpanasetckiy@users.noreply.github.com> --- mandatory/1-syntax-errors.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index bdc22dc11..bfc6a562e 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,12 +1,7 @@ // There are syntax errors in this code - can you fix it to pass the tests? -let x = 3; -let y = 4; -let z = 6; -function addNumbers(x, y, z) { - return x + y + z; +function addNumbers(a, b, c) { + return a + b + c; } -console.log(addNumbers); - let name = "Sonjide"; let age = 27; From 3da2250836ea809d79dfa94b60913327a9172bc4 Mon Sep 17 00:00:00 2001 From: ChristinaMifsud Date: Sat, 18 Feb 2023 11:16:53 +0000 Subject: [PATCH 3/7] Updated 1-syntax-errors.js Updated 1-syntax-errors.js following feedback --- mandatory/1-syntax-errors.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index bdc22dc11..9e3ee0273 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,11 +1,11 @@ // There are syntax errors in this code - can you fix it to pass the tests? -let x = 3; -let y = 4; -let z = 6; +// let x = 3; +// let y = 4; +// let z = 6; function addNumbers(x, y, z) { return x + y + z; } -console.log(addNumbers); +//console.log(addNumbers); let name = "Sonjide"; @@ -13,7 +13,7 @@ let age = 27; function introduceMe(name, age){ return `Hello, my name is ${name} and I am ${age} years old`; } -console.log(introduceMe); +//console.log(introduceMe); let a = 23; @@ -21,7 +21,7 @@ let b = 5; function getTotal(a, b) { return `The total is ${total = a + b}`; } -console.log(getTotal); +//console.log(getTotal); /* =================================================== From bf65744326aeb2c80a93b64db1bf0478c8b0535b Mon Sep 17 00:00:00 2001 From: ChristinaMifsud <102205880+christina-mifsud@users.noreply.github.com> Date: Sat, 18 Feb 2023 11:36:42 +0000 Subject: [PATCH 4/7] Update mandatory/2-logic-error.js Co-authored-by: Maksim Lukianenko <93668989+Mpanasetckiy@users.noreply.github.com> --- mandatory/2-logic-error.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 416a63947..0ad7010c8 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -19,9 +19,8 @@ function getStringLength() { } */ -function getStringLength() { - let phrase = "A wild sentence appeared!"; - return phrase.length; +function getStringLength(word) { + return word.length; } From 28e235cd16928a482ba13559d622bbbf0defc2f7 Mon Sep 17 00:00:00 2001 From: ChristinaMifsud <102205880+christina-mifsud@users.noreply.github.com> Date: Sat, 18 Feb 2023 15:56:22 +0000 Subject: [PATCH 5/7] Update mandatory/1-syntax-errors.js Co-authored-by: Irianni Munoz <82213740+munozirianni1988@users.noreply.github.com> --- mandatory/1-syntax-errors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index da7299998..a679ad760 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -6,7 +6,7 @@ function addNumbers(a, b, c) { let name = "Sonjide"; let age = 27; function introduceMe(name, age){ - return `Hello, my name is ${name} and I am ${age} years old`; + return `Hola, my name is ${name} and I am ${age} years old`; } //console.log(introduceMe); From 913ceb12d9f305673ce61c1ffbaa3f76e58f16fa Mon Sep 17 00:00:00 2001 From: ChristinaMifsud <102205880+christina-mifsud@users.noreply.github.com> Date: Sat, 18 Feb 2023 16:00:29 +0000 Subject: [PATCH 6/7] Update mandatory/1-syntax-errors.js Co-authored-by: Irianni Munoz <82213740+munozirianni1988@users.noreply.github.com> --- mandatory/1-syntax-errors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a679ad760..da7299998 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -6,7 +6,7 @@ function addNumbers(a, b, c) { let name = "Sonjide"; let age = 27; function introduceMe(name, age){ - return `Hola, my name is ${name} and I am ${age} years old`; + return `Hello, my name is ${name} and I am ${age} years old`; } //console.log(introduceMe); From 161590441906bb5b2fbfa95e8899ca7722c5ca87 Mon Sep 17 00:00:00 2001 From: ChristinaMifsud Date: Mon, 20 Feb 2023 22:41:03 +0000 Subject: [PATCH 7/7] Fixed HW Did not need to create the exact functions to match the answers in the tests. --- mandatory/1-syntax-errors.js | 2 -- mandatory/2-logic-error.js | 30 ++------------------------- mandatory/3-function-output.js | 21 +------------------ mandatory/4-tax.js | 38 +++------------------------------- 4 files changed, 6 insertions(+), 85 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index da7299998..ff863d202 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -8,7 +8,6 @@ let age = 27; function introduceMe(name, age){ return `Hello, my name is ${name} and I am ${age} years old`; } -//console.log(introduceMe); let a = 23; @@ -16,7 +15,6 @@ let b = 5; function getTotal(a, b) { return `The total is ${total = a + b}`; } -//console.log(getTotal); /* =================================================== diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 0ad7010c8..6a1dc9592 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,48 +1,22 @@ // The syntax for these functions is valid but there are some errors, find them and fix them -/* -let word =" CodeYourFuture "; -function trimWord(word) { - return word.trim(); -} -*/ -let word = " CodeYourFuture teaches coding "; -let result= word.replace (' '); + function trimWord(word) { return word.trim(); } -/* -function getStringLength() { - let text = "Turtles"; - return text.length; -} -*/ function getStringLength(word) { return word.length; } -/* -let a = 2; -let b = 3; -let c = 4; function multiply(a, b, c) { return a * b * c; } -console.log(multiply); -*/ -let x = 2; -let y = 3; -let z = 6; -function multiply(x, y, z) { - return x * y * z; -} -console.log(multiply); -/* +/* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index f48ac4cbc..580adf257 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,4 +1,5 @@ // Add comments to explain what this function does. You're meant to use Google! + function getRandomNumber() { return Math.random() * 10; } @@ -11,26 +12,6 @@ function combine2Words(word1, word2) { } /* The concat() method concatenates (joins) two or more strings. It returns a new array, containing the joined strings. */ -/* -let firstWord = "code"; -let secondWord = "your"; -let thirdWord = "future"; -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); -} -console.log(concatenate); -*/ -/* -let firstWord = "I"; -let secondWord = "like"; -let thirdWord = "pizza"; -function concatenate(firstWord, secondWord, thirdWord) { -return firstWord.concat(" ", secondWord, " ", thirdWord); -} -console.log(concatenate); -*/ let firstWord = "I"; let secondWord = "am"; diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index b975513e7..c0bbcd5b7 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -4,26 +4,12 @@ A business requires a program that calculates how much the price of a product is including sales tax Sales tax is 20% of the price of the product. */ - -function calculateSalesTax() { - let product = 15; - let salesTax = (product * 20) / 100; - return priceTotal = product + salesTax; -} -/* -function calculateSalesTax() { - let product = 17.50; +function calculateSalesTax(product) { let salesTax = (product * 20) / 100; return priceTotal = product + salesTax; } -function calculateSalesTax() { - let product = 34; - let salesTax = (product * 20) / 100; - return priceTotal = product + salesTax; -} -*/ /* CURRENCY FORMATTING @@ -34,27 +20,9 @@ function calculateSalesTax() { Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -/* -function addTaxAndFormatCurrency() { - let product = 15; - let salesTax = (product * 20) / 100; - let priceTotal = product + salesTax - - return `£${priceTotal.toFixed(2)}`; -} -*/ -/* -function addTaxAndFormatCurrency() { - let product = 17.50; - let salesTax = (product * 20) / 100; - let priceTotal = product + salesTax - - return `£${priceTotal.toFixed(2)}`; -} -*/ -function addTaxAndFormatCurrency() { - let product = 34; + +function addTaxAndFormatCurrency(product) { let salesTax = (product * 20) / 100; let priceTotal = product + salesTax