diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..e54bc4e7e 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,3 @@ -console.log("Hello world"); +let greeting = ("Hello world"); +console.log("greeting"); + diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..93a9d128b 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `greeting` - +var greeting="Hello world"; +console.log(greeting); +console.log(greeting); console.log(greeting); diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..0aa2a3035 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +let message ="This is a string"; + console.log (message) +console.log(typeof message); + -console.log(message); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..edbd82148 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,4 @@ // Start by creating a variable `message` - -console.log(message); +var greetingStart = "Hello, my name is "; +var name = "Daniel"; +console.log(greeting); diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..4494cb55a 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,20 +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 " + 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; + let total = a + b; - return "The total is total"; + return "The total is " + total; } /* -=================================================== +=================================================== ======= 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. diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..995910d8d 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..e002b0263 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -9,7 +9,10 @@ function combine2Words(word1, word2) { } function concatenate(firstWord, secondWord, thirdWord) { - // Write the body of this function to concatenate three words together. + let result = firstWord.concat(" "+ secondWord + " " +thirdWord); + + return result + // 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. } diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..df73390a7 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) { + const priceWithTax =1.2* price; +return priceWithTax; +} + /* CURRENCY FORMATTING @@ -17,7 +21,9 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(productPrice) { + return "£" +(calculateSalesTax(productPrice)).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" + ] } ] },