diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..5f29038f1 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,6 @@ -console.log("Hello world"); +console.log("Hello World. I just started learning JavaScript!"); + +console.log("I am too strong and I can do it!") +console.log(`It is my first coding exercise`) +console.log('Hello World. I just started learning JavaScript!') +console.log(45) diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..1101e702c 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,9 @@ // Start by creating a variable `greeting` +const greeting = "Hello world"; + + + +console.log(greeting); console.log(greeting); +console.log(greeting); \ No newline at end of file diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..e4552f5d3 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,11 @@ // Start by creating a variable `message` -console.log(message); +// var message = "I am a trainer in CYF"; +// var messageType = typeof message; +// console.log(messageType); + + +let message="This is a string" +let messageType = typeof message; +console.log(message) +console.log(messageType); \ No newline at end of file diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..1d4270332 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` - +var myName = "Mo nahvi"; +var greeting = "Hello, my name is"; +let message = greeting + " " + myName; console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..cec0ef6da 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,7 @@ // Start by creating a variable `message` +var name = "Mohammad" +var message = name.length; +var nameLowerCase = name.toLowerCase(); console.log(message); +console.log(nameLowerCase) diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..e799ab56e 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,7 @@ -const name = " Daniel "; - +let myName = "Mohammad "; +var greeting = "My name is "; +let sent = "and my name is 8 characters long" +let message = greeting + myName + sent; console.log(message); + + diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..5ecad1c75 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,5 +1,8 @@ // Complete the function so that it takes input parameters function multiply() { + function multiply(num1,num2) { + return num1*num2; +} // Calculate the result of the function and return it } diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..9827d7673 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,11 @@ // Declare your function first +// var result = divide(3, 4); + +// console.log(result); +function divide(num1,num2) { +return num1 / num2; +} var result = divide(3, 4); console.log(result); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..1c71a189b 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -2,4 +2,8 @@ // Call the function and assign to a variable `sum` -console.log(sum); +// console.log(sum); +function sum(num1, num2) { + return num1 + num2 +} +console.log(sum(13, 124)); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..3b5c3dc23 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,6 @@ // Declare your function here -const greeting = createLongGreeting("Daniel", 30); - -console.log(greeting); +function createLongGreeting(name,age){ + return "Hello ,my name is "+name+"and i'm "+age+ " years old" +} + const greeting = createLongGreeting("Daniel", 30); diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..9ae7a166d 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,23 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; +// var mentor1 = "Daniel"; +// var mentor2 = "Irina"; +// var mentor3 = "Mimi"; +// var mentor4 = "Rob"; +// var mentor5 = "Yohannes"; + +const mentor1 = "Daniel"; +const mentor2 = "Irina"; +const mentor3 = "Mimi"; +const mentor4 = "Rob"; +const mentor5 = "Yohannes"; + +function nameToUpperCase(name){ + return name.toUpperCase(); +} +function greeting(name){ + return `Hello ${nameToUpperCase(name)}`; +} +function result(name){ + return console.log(greeting(name)); +} +result(mentor1); +result(mentor3) \ No newline at end of file diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..adf6ac4e1 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,16 +1,16 @@ // 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; +function getTotal(a, b){ + 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 9cca7603b..881472346 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,16 @@ // 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..1a558af4d 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,16 +1,17 @@ // Add comments to explain what this function does. You're meant to use Google! + // It get a number between 0 to 10 function getRandomNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! +//It connect the word together function combine2Words(word1, word2) { return word1.concat(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.concat(" " + secondWord).concat(" " + thirdWord) } /* diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..0936362f6 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,12 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +function calculateSalesTax(newPrice) { + return newPrice * 0.2 + newPrice + +} + +console.log(calculateSalesTax(15)) /* CURRENCY FORMATTING @@ -17,7 +22,13 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(addPrice) { + let newP= calculateSalesTax(addPrice); + let deci = newP.toFixed(2); + return `£ ${deci}` +} + +console.log(addTaxAndFormatCurrency(50)) /* =================================================== 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" + ] } ] },