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..91b584b6b 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 "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}`; } /* @@ -24,7 +26,6 @@ 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); }); 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..3f02163a4 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -2,15 +2,17 @@ function getRandomNumber() { return Math.random() * 10; } +//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); } - -function concatenate(firstWord, secondWord, thirdWord) { +// It combines 2 words. +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}`; } /* @@ -23,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"); }); diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..d915fb92e 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,10 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +function calculateSalesTax(sales) { + const tax = 0.2 * sales; + return tax + sales; +} /* CURRENCY FORMATTING @@ -17,7 +20,9 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(sales) { + return "£" + calculateSalesTax(sales).toFixed(2); +} /* ===================================================