From 76dfc9c78b5e1f6861c84480c57e529d05910c07 Mon Sep 17 00:00:00 2001 From: monahvi Date: Sun, 20 Nov 2022 21:51:33 +0000 Subject: [PATCH 1/3] JavaScript-Core-1-Mo nahvi-Coursework-Week1 --- exercises/B-hello-world/exercise.js | 4 +++- exercises/C-variables/exercise.js | 2 ++ exercises/D-strings/exercise.js | 6 +++++- exercises/E-strings-concatenation/exercise.js | 4 +++- exercises/F-strings-methods/exercise.js | 4 ++++ exercises/F-strings-methods/exercise2.js | 8 ++++++-- 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..3a0aa1287 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,3 @@ -console.log("Hello world"); +console.log("Hello World. I just started learning JavaScript!"); + +console.log("I am too strong and I can do it!") diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..ff050fb07 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); diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..ed4b2f29a 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,7 @@ // Start by creating a variable `message` -console.log(message); +var message = "I am a trainer in CYF"; +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..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); + + From b1805f25bc06f1406b924dfd0f246612e468077c Mon Sep 17 00:00:00 2001 From: monahvi Date: Tue, 29 Nov 2022 20:13:49 +0000 Subject: [PATCH 2/3] London class 9 - Mo nahvi- JavaScript - Core - 1 - Week1 --- exercises/B-hello-world/exercise.js | 3 ++ exercises/C-variables/exercise.js | 6 +++- exercises/D-strings/exercise.js | 10 +++++-- exercises/K-functions-parameters/exercise.js | 3 ++ exercises/K-functions-parameters/exercise2.js | 6 ++++ exercises/K-functions-parameters/exercise4.js | 6 +++- exercises/K-functions-parameters/exercise5.js | 7 +++-- exercises/L-functions-nested/exercise.js | 28 +++++++++++++++---- mandatory/1-syntax-errors.js | 10 +++---- mandatory/2-logic-error.js | 7 ++--- mandatory/3-function-output.js | 5 ++-- mandatory/4-tax.js | 15 ++++++++-- package.json | 12 ++++++-- 13 files changed, 89 insertions(+), 29 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index 3a0aa1287..5f29038f1 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1,3 +1,6 @@ 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 ff050fb07..1101e702c 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,5 +1,9 @@ // Start by creating a variable `greeting` -var greeting = "Hello world"; +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 ed4b2f29a..e4552f5d3 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,7 +1,11 @@ // Start by creating a variable `message` -var message = "I am a trainer in CYF"; -var messageType = typeof message; -console.log(messageType); +// 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/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..05c29e157 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..b3abe4625 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..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" + ] } ] }, From 89aaeaf176e4a3cc3f403d629cf58bdb0b27987f Mon Sep 17 00:00:00 2001 From: monahvi Date: Thu, 1 Dec 2022 17:35:08 +0000 Subject: [PATCH 3/3] some change --- exercises/K-functions-parameters/exercise4.js | 6 +++--- mandatory/2-logic-error.js | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 05c29e157..1c71a189b 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -3,7 +3,7 @@ // Call the function and assign to a variable `sum` // console.log(sum); -function sum(num1,num2){ - return num1+num2 +function sum(num1, num2) { + return num1 + num2 } -console.log(sum(13,124)); \ No newline at end of file +console.log(sum(13, 124)); \ No newline at end of file diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index b3abe4625..881472346 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -10,6 +10,7 @@ function getStringLength(word) { function multiply(a, b, c) { return a * b * c; + } /*