From 09dcb6e28cb45c842acc89d569df27fc564db05c Mon Sep 17 00:00:00 2001 From: Dawit-Dev <100426510+Dawit-Dev@users.noreply.github.com> Date: Fri, 25 Feb 2022 15:51:37 +0000 Subject: [PATCH 1/6] My first console.log --- exercises/B-hello-world/exercise.js | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..80a4db1f0 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,2 @@ console.log("Hello world"); +console.log("Hello world I'm so excited today"); From 3956340576bf872ba9de7d365f6d9928b0015a9d Mon Sep 17 00:00:00 2001 From: Dawit-Dev <100426510+Dawit-Dev@users.noreply.github.com> Date: Fri, 25 Feb 2022 16:56:49 +0000 Subject: [PATCH 2/6] Multiple console logs --- exercises/B-hello-world/exercise.js | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index 80a4db1f0..ca943698e 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1,2 +1,3 @@ console.log("Hello world"); console.log("Hello world I'm so excited today"); +console.log("Hello world I'm so excited today because I have started to learn JavaScript"); From 84795225cd0eb3d18d1a13e058fba675e7d7dc7a Mon Sep 17 00:00:00 2001 From: Dawit-Dev <100426510+Dawit-Dev@users.noreply.github.com> Date: Sun, 27 Feb 2022 15:38:02 +0000 Subject: [PATCH 3/6] Completed exercises A - C --- exercises/B-hello-world/exercise.js | 8 ++++++-- exercises/C-variables/README.md | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index ca943698e..ff5439a8b 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1,3 +1,7 @@ console.log("Hello world"); -console.log("Hello world I'm so excited today"); -console.log("Hello world I'm so excited today because I have started to learn JavaScript"); +console.log("Hello world"); +// console.log(Hello); + +var greeting = "Hello, I'm learning JavaScript"; +greeting = "Hello world"; +console.log(greeting); \ No newline at end of file diff --git a/exercises/C-variables/README.md b/exercises/C-variables/README.md index 40859b3a8..d7c16c0dc 100644 --- a/exercises/C-variables/README.md +++ b/exercises/C-variables/README.md @@ -1,4 +1,4 @@ -When you write code, you'll want to create shortcuts to data values so you can don't have to write out the same value every time. +When you write code, you'll want to create shortcuts to data values so you don't have to write out the same value every time. We can use _variable_ to create a reference to a value. From 2a2e775dae36264cd77e710d679d79f218dba7d3 Mon Sep 17 00:00:00 2001 From: Dawit-Dev <100426510+Dawit-Dev@users.noreply.github.com> Date: Tue, 2 Aug 2022 15:24:49 +0100 Subject: [PATCH 4/6] Exercise b completed --- exercises/C-variables/exercise.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..dd31c60bb 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,8 @@ // Start by creating a variable `greeting` +var greeting; +greeting = "Hello World"; +console.log(greeting); +console.log(greeting); +console.log(greeting); console.log(greeting); From 7b524f2f406b569cdf061ecf86c9f1a10aa92fd4 Mon Sep 17 00:00:00 2001 From: Dawit-Dev <100426510+Dawit-Dev@users.noreply.github.com> Date: Tue, 2 Aug 2022 15:41:34 +0100 Subject: [PATCH 5/6] Completed mandatory exercise --- mandatory/1-syntax-errors.js | 13 ++++++++----- mandatory/2-logic-error.js | 12 ++++++------ mandatory/3-function-output.js | 10 +++++++++- mandatory/4-tax.js | 15 ++++++++++++--- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..9d6a400d8 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,16 +1,19 @@ // 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"; + +} +console.log(introduceMe("Dawit", 50)) function getTotal(a, b) { - total = a ++ b; + let 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..29dbb2dd6 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,17 +1,17 @@ // 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; } +console.log(multiply(2, 5, 6)); /* =================================================== diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..10441cfde 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -2,16 +2,24 @@ function getRandomNumber() { return Math.random() * 10; } - + //* +// The random() method returns a random value that is greater than or equal to 0.0 and less than 1.0. +//* // Add comments to explain what this function does. You're meant to use Google! function combine2Words(word1, word2) { return word1.concat(word2); } +//* +// This function will join the two words without space between them. +//* 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); } + +console.log(concatenate("Code", "Your","Future")); /* =================================================== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..0e859e465 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) { + let salesTax = (price * 20) / 100; + let totalPrice = price + salesTax; + return totalPrice; +} /* CURRENCY FORMATTING @@ -17,8 +21,13 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} - +function addTaxAndFormatCurrency(amount) { + // const total = calculateSalesTax(amount); + // const formattedTotal = `£${total.toFixed(2)}`; + // return formattedTotal; + return `£${calculateSalesTax(amount).toFixed(2)}`; +} +console.log(addTaxAndFormatCurrency(17.5)); /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== From d354fff886f5f75ccf134b36d8de8d4a57e04fc5 Mon Sep 17 00:00:00 2001 From: Dawit-Dev <100426510+Dawit-Dev@users.noreply.github.com> Date: Tue, 2 Aug 2022 16:16:47 +0100 Subject: [PATCH 6/6] Completed exercise --- exercises/D-strings/exercise.js | 2 ++ exercises/E-strings-concatenation/exercise.js | 5 ++++- exercises/F-strings-methods/exercise.js | 7 ++++++- exercises/F-strings-methods/exercise2.js | 8 ++++++-- exercises/G-numbers/exercise.js | 11 +++++++++++ exercises/I-floats/exercise.js | 6 ++++++ exercises/J-functions/exercise.js | 2 ++ exercises/J-functions/exercise2.js | 4 ++++ exercises/K-functions-parameters/exercise.js | 4 +++- exercises/K-functions-parameters/exercise2.js | 5 ++++- exercises/K-functions-parameters/exercise3.js | 5 ++++- exercises/K-functions-parameters/exercise4.js | 5 +++++ exercises/K-functions-parameters/exercise5.js | 4 ++++ exercises/L-functions-nested/exercise.js | 9 +++++++++ 14 files changed, 70 insertions(+), 7 deletions(-) diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..f2422aefc 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` +var message = "This is a string"; console.log(message); +console.log(typeof (message)); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..eecdc731e 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` - +var greetingStart = "Hello, my name is "; +var name = "Dawit"; +var message = greetingStart + name; console.log(message); + diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..14cc464d2 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,8 @@ // Start by creating a variable `message` - +var name = "Dawit"; +var messageStart = "My name is"; +var messageMiddle = "and my name is"; +var messageEnd = "charactors long"; +var nameLength = name.nameLength; +var message = messageStart + " " + name + " " + messageMiddle + " " + name.length + " " + messageEnd; console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..86da76f23 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,7 @@ -const name = " Daniel "; - +var name = " Dawit "; +var messageStart = "My name is"; +var messageMiddle = "and my name is"; +var messageEnd = "characters long"; +var nameLength = name.nameLength; +var message = messageStart + " " + name.trim() + " " + messageMiddle + " " + name.length + " " + messageEnd; console.log(message); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..5785139eb 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,12 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +var numberOfStudents = 15; +var student = "Number of students: "; +var numberOfMentors = 8; +var mentors = "Number of mentors: "; + +var total = numberOfStudents + numberOfMentors; +var totalOfAll = "Total number of students and mentors: "; + +console.log(student + numberOfStudents); +console.log(mentors + numberOfMentors); +console.log(totalOfAll + total); \ No newline at end of file diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..5c3e2bdaf 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,8 @@ var numberOfStudents = 15; var numberOfMentors = 8; + +let total = numberOfStudents + numberOfMentors +let studentsPercentage = numberOfStudents / total * 100 +console.log(Math.round(studentsPercentage) + "%") +let mentorsPercentage = (numberOfMentors * 100) / total +console.log(Math.round(mentorsPercentage) + "%") diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..5ff2c92e2 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,5 +1,7 @@ function halve(number) { + var number = 12; // complete the function here + return number - (number / 2); } var result = halve(12); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..05aaf247b 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,7 +1,11 @@ function triple(number) { // complete function here + var number = 12; + return number = (number * 3); + } var result = triple(12); console.log(result); + diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..186477d47 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,9 +1,11 @@ // Complete the function so that it takes input parameters -function multiply() { +function multiply(a, b) { // Calculate the result of the function and return it + return result = a * b; } // Assign the result of calling the function the variable `result` var result = multiply(3, 4); console.log(result); + diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..cddf63e7b 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,8 @@ // Declare your function first +function divide(a, b) { + return result = a / b; +} -var result = divide(3, 4); +var result = divide(1.5, 2); console.log(result); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..5ca0cd138 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,8 @@ // Write your function here +function createGreeting(name) { + return greeting = `Hello, my name is ${name}` +} -var greeting = createGreeting("Daniel"); +var greeting = createGreeting("Dawit"); console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..fcb60ec6d 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,10 @@ // Declare your function first +function passing(a, b) { + return sum = a + b; +} // Call the function and assign to a variable `sum` +var sum = passing(13, 124) console.log(sum); + diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..49996fc3c 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,9 @@ // Declare your function here +function createLongGreeting(name, age) { + return greeting = "Hello, my name is " + name + "and my age is " + age + "years old"; +} const greeting = createLongGreeting("Daniel", 30); console.log(greeting); + diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..1e24993d9 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,12 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +function mentors(name) { + return `HELLO ${name.toUpperCase()}!`; +} +console.log(mentors(mentor1)) +console.log(mentors(mentor2)) +console.log(mentors(mentor3)) +console.log(mentors(mentor4)) +console.log(mentors(mentor5))