diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..6156b9a3d 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,3 @@ // Start by creating a variable `greeting` - +const greeting = "Hello" console.log(greeting); diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..7d2497cfc 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,4 @@ // Start by creating a variable `message` - -console.log(message); +var message = "CYF Rocks"; +var messageType = typeof message; +console.log( messageType); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..38676e32d 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 greeting = "Hello"; +var myName = "Khaya"; +console.log(greeting + " " + myName) \ No newline at end of file diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..638ddf34d 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,4 @@ // Start by creating a variable `message` - -console.log(message); +var message = "Khaya"; +var messageLength = message.length; +console.log(messageLength); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..87459c5ac 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,3 @@ const name = " Daniel "; - -console.log(message); +const message = name.length; +console.log("My name is " + name.trim() + "and my name is " + message + " characters long" ); diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index 0a21afd1b..dbd0453bf 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,17 +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"; +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,19 +25,22 @@ To run these tests type `node 1-syntax-errors.js` into your terminal =================================================== */ -const util = require('util'); +const until = require("until"); function test(test_name, actual, expected) { let status; if (actual === expected) { status = "PASSED"; } else { - status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`; + status = `FAILED: expected: ${until.inspect(expected) + } + but your function returned:${until.inspect(actual)}`; } console.log(`${test_name}: ${status}`); } + test("fixed addNumbers function - case 1", addNumbers(3, 4, 6), 13); test("fixed introduceMe function", introduceMe("Sonjide", 27), "Hello, my name is Sonjide and I am 27 years old"); -test("fixed getTotal function", getTotal(23, 5), "The total is 28"); +test("fixed getTotal function", getTotal(23, 5), "The total is 28"); \ No newline at end of file diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 3c578ad87..5c2022476 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 getWordLength(word) { - return "word".length(); + return word.length(); } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; } /* diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index c9e41c691..212747d4f 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(price) { + const amount = price * 0.2; + return amount; +} /* CURRENCY FORMATTING @@ -17,7 +20,10 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(total) { + const afterTax = calculateSalesTax(total).toFixed(2); + return `£${afterTax}`; +} /* ===================================================