From bf4ecae42cb225a17a2a5f7f17b1ccac25d4b6f8 Mon Sep 17 00:00:00 2001 From: hamda86 <104569022+hamda86@users.noreply.github.com> Date: Sat, 18 Feb 2023 13:10:56 +0000 Subject: [PATCH 1/5] Update 1-syntax-error.js I fixed all the syntax error. --- README.md | 4 +--- mandatory/1-syntax-errors.js | 42 ++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 6611d00c3..7743addab 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ If you think you need to do more practice with the basics, then you can find som ## Setting up your code editor - There are some tools that will help you to write code. One of these, [Prettier](https://prettier.io/), formats your code, making it easier for you and others to read. ### 1. Install prettier @@ -25,10 +24,9 @@ There are some tools that will help you to write code. One of these, [Prettier]( - Search for `editor format` - Set `editor.formatOnSave` and `editor.formatOnPaste` to true - ## Running the code/tests -The files for the mandatory/extra exercises are intended to be run as jest tests. +The files for the mandatory/extra exercises are intended to be run as jest tests. - Once you have cloned the repository, run `npm install` once in the terminal to install jest (and any necessary dependencies). - To run the tests for all mandatory/extra exercises, run `npm test` diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index d9e004465..52b21d1ca 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,19 +1,22 @@ // 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`; +function introduceMe(name, age) { + return `Hello, my {name}`; + is; + ("and I am $age years old`;"); -function getTotal(a, b) { - total = a ++ b; + function getTotal(a, b) { + total = a++; + b; - return "The total is total"; -} + return "The total is total"; + } -/* + /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== @@ -25,16 +28,17 @@ To run the tests for just this one file, type `npm test -- --testPathPattern 1-s =================================================== */ -test("addNumbers adds numbers correctly", () => { - expect(addNumbers(3, 4, 6)).toEqual(13); -}); + test("addNumbers adds numbers correctly", () => { + expect(addNumbers(3, 4, 6)).toEqual(13); + }); -test("introduceMe function returns the correct string", () => { - expect(introduceMe("Sonjide", 27)).toEqual( - "Hello, my name is Sonjide and I am 27 years old" - ); -}); + test("introduceMe function returns the correct string", () => { + expect(introduceMe("Sonjide", 27)).toEqual( + "Hello, my name is Sonjide and I am 27 years old" + ); + }); -test("getTotal returns a string describing the total", () => { - expect(getTotal(23, 5)).toEqual("The total is 28"); -}); + test("getTotal returns a string describing the total", () => { + expect(getTotal(23, 5)).toEqual("The total is 28"); + }); +} From 28d5546a2ea982f3d5b5754968cc0a24f5bcf8da Mon Sep 17 00:00:00 2001 From: hamda86 <104569022+hamda86@users.noreply.github.com> Date: Fri, 24 Feb 2023 12:47:00 +0000 Subject: [PATCH 2/5] Update --- mandatory/1-syntax-errors.js | 6 +++--- mandatory/2-logic-error.js | 7 +++---- mandatory/3-function-output.js | 6 ++++-- mandatory/4-tax.js | 9 +++++++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index 52b21d1ca..b3420d632 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -5,15 +5,15 @@ function addNumbers(a, b, c) { } function introduceMe(name, age) { - return `Hello, my {name}`; + return `Hello, my ${name} and I am ${age} years old; is; ("and I am $age years old`;"); function getTotal(a, b) { - total = a++; + let 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 9eb8c8cd7..ff5b064e1 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,15 @@ // 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; } /* diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..59f2d449a 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -2,17 +2,19 @@ function getRandomNumber() { return Math.random() * 10; } +//It gives random number between 0 to 1. // Add comments to explain what this function does. You're meant to use Google! function combine2Words(word1, word2) { return word1.concat(word2); } - -function concatenate(firstWord, secondWord, thirdWord) { +// It combines 2 words. +function concatenate("I", "am", "coding") { // 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 ===== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..f70cd1639 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,9 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +function calculateSalesTax(price) { + return price * 1.2; +} /* CURRENCY FORMATTING @@ -17,7 +19,10 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(ourSales) { + let salesWithTax = calculateSalesTax(ourSales); + return "£${salesWithTax.toFixed(2)}"; +} /* =================================================== From 1d62817a3afc5074c3b75c4c006f4248e9aad0f6 Mon Sep 17 00:00:00 2001 From: hamda86 <104569022+hamda86@users.noreply.github.com> Date: Fri, 24 Feb 2023 13:05:45 +0000 Subject: [PATCH 3/5] Update 1-syntax-error.js --- mandatory/1-syntax-errors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index b3420d632..2ca63a7a7 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -6,8 +6,8 @@ function addNumbers(a, b, c) { function introduceMe(name, age) { return `Hello, my ${name} and I am ${age} years old; - is; - ("and I am $age years old`;"); + +} function getTotal(a, b) { let total = a++; From 1c1c3ff8d8807b669ad7333c564e7060676874f5 Mon Sep 17 00:00:00 2001 From: hamda86 <104569022+hamda86@users.noreply.github.com> Date: Sat, 25 Feb 2023 11:15:07 +0000 Subject: [PATCH 4/5] update class --- mandatory/1-syntax-errors.js | 42 +++++++++++++++------------------- mandatory/3-function-output.js | 6 ++--- mandatory/4-tax.js | 10 ++++---- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index 2ca63a7a7..f18ac63ec 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -5,18 +5,16 @@ function addNumbers(a, b, c) { } function introduceMe(name, age) { - return `Hello, my ${name} and I am ${age} years old; - + return `Hello, my ${name} and I am ${age} years old`; } - function getTotal(a, b) { - let total = a++; - b; +function getTotal(a, b) { + total = a + b; - return 'The total is ${total}'; - } + return "The total is ${total}"; +} - /* +/* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== @@ -27,18 +25,16 @@ To run the tests for just this one file, type `npm test -- --testPathPattern 1-s =================================================== */ - - test("addNumbers adds numbers correctly", () => { - expect(addNumbers(3, 4, 6)).toEqual(13); - }); - - test("introduceMe function returns the correct string", () => { - expect(introduceMe("Sonjide", 27)).toEqual( - "Hello, my name is Sonjide and I am 27 years old" - ); - }); - - test("getTotal returns a string describing the total", () => { - expect(getTotal(23, 5)).toEqual("The total is 28"); - }); -} +test("addNumbers adds numbers correctly", () => { + expect(addNumbers(3, 4, 6)).toEqual(13); +}); + +test("introduceMe function returns the correct string", () => { + expect(introduceMe("Sonjide", 27)).toEqual( + "Hello, my name is Sonjide and I am 27 years old" + ); +}); + +test("getTotal returns a string describing the total", () => { + expect(getTotal(23, 5)).toEqual("The total is 28"); +}); diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 59f2d449a..63d10d295 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -2,19 +2,19 @@ function getRandomNumber() { return Math.random() * 10; } -//It gives random number between 0 to 1. +//It gives random number between 0 to 10. // Add comments to explain what this function does. You're meant to use Google! function combine2Words(word1, word2) { return word1.concat(word2); } // It combines 2 words. -function concatenate("I", "am", "coding") { +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} ${secondword} ${thirdword}'); } - /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index f70cd1639..d915fb92e 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,8 +5,9 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax(price) { - return price * 1.2; +function calculateSalesTax(sales) { + const tax = 0.2 * sales; + return tax + sales; } /* @@ -19,9 +20,8 @@ function calculateSalesTax(price) { Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency(ourSales) { - let salesWithTax = calculateSalesTax(ourSales); - return "£${salesWithTax.toFixed(2)}"; +function addTaxAndFormatCurrency(sales) { + return "£" + calculateSalesTax(sales).toFixed(2); } /* From 538ee07d721e35e18bdc26509efca079a75b1292 Mon Sep 17 00:00:00 2001 From: hamda86 <104569022+hamda86@users.noreply.github.com> Date: Sat, 25 Feb 2023 12:18:44 +0000 Subject: [PATCH 5/5] Update Backtick I solved the error. I used a quote '' INSTEAD of backtick `` --- mandatory/1-syntax-errors.js | 5 +++-- mandatory/3-function-output.js | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index f18ac63ec..91b584b6b 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -5,13 +5,14 @@ function addNumbers(a, b, c) { } function introduceMe(name, age) { - return `Hello, my ${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; - return "The total is ${total}"; + return `The total is ${total}`; } /* diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 63d10d295..3f02163a4 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -12,7 +12,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} ${secondword} ${thirdword}'); + return `${firstword} ${secondword} ${thirdword}`; } /* @@ -25,7 +25,6 @@ To run the tests for just this one file, type `npm test -- --testPathPattern 3-f (Reminder: You must have run `npm install` one time before this will work!) ================================== */ - test("concatenate example #1", () => { expect(concatenate("code", "your", "future")).toEqual("code your future"); });