From 112402f46d65d8cb6c8ae5cb27d91c7c4eb0408a Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 22:45:16 +0100 Subject: [PATCH 01/21] exercise done B-hello-world --- week-1/1-exercises/B-hello-world/exercise.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/B-hello-world/exercise.js b/week-1/1-exercises/B-hello-world/exercise.js index b179ee9..cc7e44f 100644 --- a/week-1/1-exercises/B-hello-world/exercise.js +++ b/week-1/1-exercises/B-hello-world/exercise.js @@ -1 +1,2 @@ -console.log("Hello world"); +console.log("Hello world. I just started learning javascript"); +console.log(2020); From 82da683c4cb6e6cca25bc3065bf07354b43f1448 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 22:46:45 +0100 Subject: [PATCH 02/21] exercise done C-variables --- week-1/1-exercises/C-variables/exercise.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/C-variables/exercise.js b/week-1/1-exercises/C-variables/exercise.js index a6bbb97..a1af969 100644 --- a/week-1/1-exercises/C-variables/exercise.js +++ b/week-1/1-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); From 375a8784d969a33c4f00deaac37dc6e9d9e2e08b Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 22:50:41 +0100 Subject: [PATCH 03/21] exercise done D-strings --- week-1/1-exercises/D-strings/exercise.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/week-1/1-exercises/D-strings/exercise.js b/week-1/1-exercises/D-strings/exercise.js index 2cffa6a..2d108e2 100644 --- a/week-1/1-exercises/D-strings/exercise.js +++ b/week-1/1-exercises/D-strings/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +var message = "This is a string"; +var messageType = typeof message; +console.log(messageType); // logs 'string' console.log(message); From a6f2b32e87cb69720c24373538f54c5c4d5dbdd0 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 22:53:57 +0100 Subject: [PATCH 04/21] exercise done E-strings-concatenation --- week-1/1-exercises/E-strings-concatenation/exercise.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/E-strings-concatenation/exercise.js b/week-1/1-exercises/E-strings-concatenation/exercise.js index 2cffa6a..6943e8c 100644 --- a/week-1/1-exercises/E-strings-concatenation/exercise.js +++ b/week-1/1-exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,7 @@ // Start by creating a variable `message` +var greetingStart = "Hello, my name is "; +var name = "Berhane"; -console.log(message); +var greeting = greetingStart + name; + +console.log(greeting); // Logs "Hello, my name is Daniel" From 2d5a4e4b0da7b0adf2b9f2c46c0dc47625fd2db5 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:07:45 +0100 Subject: [PATCH 05/21] exercise1 done F-strings-method --- week-1/1-exercises/F-strings-methods/exercise.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/F-strings-methods/exercise.js b/week-1/1-exercises/F-strings-methods/exercise.js index 2cffa6a..3b95944 100644 --- a/week-1/1-exercises/F-strings-methods/exercise.js +++ b/week-1/1-exercises/F-strings-methods/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` - +var name = "Berhane"; +var nameLength = name.length; +var message = "My name is " + name +" and my name is " + nameLength + " characters long" +console.log(nameLength); // Logs 6 console.log(message); From ee55d1560e155173f4f2f53826d6a0e29462a458 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:14:16 +0100 Subject: [PATCH 06/21] exercise2 done F-strings-method --- week-1/1-exercises/F-strings-methods/exercise2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week-1/1-exercises/F-strings-methods/exercise2.js b/week-1/1-exercises/F-strings-methods/exercise2.js index b4b4694..068ec34 100644 --- a/week-1/1-exercises/F-strings-methods/exercise2.js +++ b/week-1/1-exercises/F-strings-methods/exercise2.js @@ -1,3 +1,3 @@ -const name = " Daniel "; - -console.log(message); +const name = " My name is Berhane and my name is 7 characters long "; +name.trim(); +console.log(name); From 870aa1c85cfc1b7eeac9d4f042a92bd4f2b5fc5b Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:20:00 +0100 Subject: [PATCH 07/21] exercise done G-numbers --- week-1/1-exercises/G-numbers/exercise.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/week-1/1-exercises/G-numbers/exercise.js b/week-1/1-exercises/G-numbers/exercise.js index 49e7bc0..f92d940 100644 --- a/week-1/1-exercises/G-numbers/exercise.js +++ b/week-1/1-exercises/G-numbers/exercise.js @@ -1 +1,5 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +var numberOfStudents = 15; +var numberOfMentors = 8; +var sum = numberOfStudents + numberOfMentors; +console.log("Total numnber of students and mentors:" + sum); From 3e8e82cdd6cc7352d2a5e010136729366f16b939 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:39:44 +0100 Subject: [PATCH 08/21] exercise done I-floats --- week-1/1-exercises/I-floats/exercise.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/week-1/1-exercises/I-floats/exercise.js b/week-1/1-exercises/I-floats/exercise.js index a5bbcd8..14730c2 100644 --- a/week-1/1-exercises/I-floats/exercise.js +++ b/week-1/1-exercises/I-floats/exercise.js @@ -1,2 +1,7 @@ var numberOfStudents = 15; var numberOfMentors = 8; +var stuPercentile = numberOfStudents/23*100; +var mentorpercentile = numberOfMentors/23*100; +console.log("Percentage Students:" +stuPercentile + "%" ); +console.log("Percentage Mentors:" + mentorpercentile + "%"); + From 8373dd5b49af65a43a6181b5f06a4702e46b3ee0 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:42:14 +0100 Subject: [PATCH 09/21] exercise done I-floats update --- week-1/1-exercises/I-floats/exercise.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/week-1/1-exercises/I-floats/exercise.js b/week-1/1-exercises/I-floats/exercise.js index 14730c2..f88e40a 100644 --- a/week-1/1-exercises/I-floats/exercise.js +++ b/week-1/1-exercises/I-floats/exercise.js @@ -2,6 +2,8 @@ var numberOfStudents = 15; var numberOfMentors = 8; var stuPercentile = numberOfStudents/23*100; var mentorpercentile = numberOfMentors/23*100; +stuPercentile = Math.round(stuPercentile); +mentorpercentile = Math.round(mentorpercentile); console.log("Percentage Students:" +stuPercentile + "%" ); console.log("Percentage Mentors:" + mentorpercentile + "%"); From f5bc22432e3ccc3cb848dd2fce967f5a0bfc00b9 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:46:59 +0100 Subject: [PATCH 10/21] exercise done J-functions --- week-1/1-exercises/J-functions/exercise.js | 1 + 1 file changed, 1 insertion(+) diff --git a/week-1/1-exercises/J-functions/exercise.js b/week-1/1-exercises/J-functions/exercise.js index 0ae5850..e9ba2f0 100644 --- a/week-1/1-exercises/J-functions/exercise.js +++ b/week-1/1-exercises/J-functions/exercise.js @@ -1,5 +1,6 @@ function halve(number) { // complete the function here + return number/2; } var result = halve(12); From 45bbcb7456d1ebb43e8341f5315d327ab572c152 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:49:15 +0100 Subject: [PATCH 11/21] exercise done J-functions --- week-1/1-exercises/J-functions/exercise.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/J-functions/exercise.js b/week-1/1-exercises/J-functions/exercise.js index e9ba2f0..c1b5db3 100644 --- a/week-1/1-exercises/J-functions/exercise.js +++ b/week-1/1-exercises/J-functions/exercise.js @@ -4,5 +4,8 @@ function halve(number) { } var result = halve(12); - +var result2 = halve(32); +var result3 = halve(3); console.log(result); +console.log(result2); +console.log(result3); From ca4400708cdeba988faa82608773828f06c7fdc8 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:50:45 +0100 Subject: [PATCH 12/21] exercise2 done J-functions --- week-1/1-exercises/J-functions/exercise2.js | 1 + 1 file changed, 1 insertion(+) diff --git a/week-1/1-exercises/J-functions/exercise2.js b/week-1/1-exercises/J-functions/exercise2.js index 82ef5e7..468d455 100644 --- a/week-1/1-exercises/J-functions/exercise2.js +++ b/week-1/1-exercises/J-functions/exercise2.js @@ -1,5 +1,6 @@ function triple(number) { // complete function here + return number * 3; } var result = triple(12); From 4b56746e1905a5549a45933d12bc9e217130b7da Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:54:28 +0100 Subject: [PATCH 13/21] exercise done K-functions-parameters --- week-1/1-exercises/K-functions-parameters/exercise.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise.js b/week-1/1-exercises/K-functions-parameters/exercise.js index 8d5db5e..71969d1 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise.js +++ b/week-1/1-exercises/K-functions-parameters/exercise.js @@ -1,6 +1,7 @@ // Complete the function so that it takes input parameters -function multiply() { +function multiply(num1,num2) { // Calculate the result of the function and return it + return num1 * num2; } // Assign the result of calling the function the variable `result` From 455ba21f520416c45b7bfa7711e2cdebe2a0b290 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:56:28 +0100 Subject: [PATCH 14/21] exercise2 done K-functions-parameters --- week-1/1-exercises/K-functions-parameters/exercise2.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/week-1/1-exercises/K-functions-parameters/exercise2.js b/week-1/1-exercises/K-functions-parameters/exercise2.js index db7a890..1dcf0e0 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise2.js +++ b/week-1/1-exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,10 @@ // Declare your function first +function divide(num1, num2) { + // Calculate the result of the function and return it + return num1 / num2; +} +// Assign the result of calling the function the variable `result` var result = divide(3, 4); console.log(result); From dd3dd6dea650121477a80a10fe80ea4372288d7f Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 20 Jun 2020 00:02:07 +0100 Subject: [PATCH 15/21] exercise3 done K-functions-parameters --- week-1/1-exercises/K-functions-parameters/exercise3.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/week-1/1-exercises/K-functions-parameters/exercise3.js b/week-1/1-exercises/K-functions-parameters/exercise3.js index 537e9f4..fbfbf0c 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise3.js +++ b/week-1/1-exercises/K-functions-parameters/exercise3.js @@ -1,4 +1,7 @@ // Write your function here +function createGreeting(name){ + return "Hello, my name is " + name; +} var greeting = createGreeting("Daniel"); From fe488ea150d7898bb3acc26ad8bbd3aced7737ce Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 20 Jun 2020 00:05:10 +0100 Subject: [PATCH 16/21] exercise4 done K-functions-parameters --- week-1/1-exercises/K-functions-parameters/exercise4.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/week-1/1-exercises/K-functions-parameters/exercise4.js b/week-1/1-exercises/K-functions-parameters/exercise4.js index 7ab4458..067cb5f 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise4.js +++ b/week-1/1-exercises/K-functions-parameters/exercise4.js @@ -1,4 +1,9 @@ // Declare your function first +function addition(num1, num2) { + return num1 + num2; +} + +sum = addition(13, 124); // Call the function and assign to a variable `sum` From 4d43363457d3000ca158f872497b901deef6e9ff Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 20 Jun 2020 00:07:51 +0100 Subject: [PATCH 17/21] exercise5 done K-functions-parameters --- week-1/1-exercises/K-functions-parameters/exercise5.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/week-1/1-exercises/K-functions-parameters/exercise5.js b/week-1/1-exercises/K-functions-parameters/exercise5.js index 7c5bcd6..23d1783 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise5.js +++ b/week-1/1-exercises/K-functions-parameters/exercise5.js @@ -1,4 +1,8 @@ // Declare your function here +function createLongGreeting(name, age){ + return "Hello, my name is " + name + " and I'm " + age + " years old" + +} const greeting = createLongGreeting("Daniel", 30); From 64e0da94f7bdbfe2c452508dff5aef378e252203 Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 20 Jun 2020 00:55:14 +0100 Subject: [PATCH 18/21] syntax corrected --- week-1/2-mandatory/1-syntax-errors.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/week-1/2-mandatory/1-syntax-errors.js b/week-1/2-mandatory/1-syntax-errors.js index 6910f28..353fb45 100644 --- a/week-1/2-mandatory/1-syntax-errors.js +++ b/week-1/2-mandatory/1-syntax-errors.js @@ -2,18 +2,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"; +} -function getAddition(a, b) { - total = a ++ b +function getRemainder(a, b) { + // Use string interpolation here - return "The total is %{total}" + return `The remainder is ${a%b}`; } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -23,12 +24,12 @@ function getAddition(a, b) { function test(test_name, expr) { let status; if (expr) { - status = "PASSED" + status = "PASSED" ; } else { - status = "FAILED" + status = "FAILED" ; } - console.log(`${test_name}: ${status}`) + console.log(`${test_name}: ${status}`) ; } test("fixed addNumbers function - case 1", addNumbers(3,4,6) === 13) From 8c623d686397c5d50d3dbb745b9bc2bf5ff348a0 Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 20 Jun 2020 01:03:46 +0100 Subject: [PATCH 19/21] logic error corrected --- week-1/2-mandatory/2-logic-error.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/week-1/2-mandatory/2-logic-error.js b/week-1/2-mandatory/2-logic-error.js index 1e0a9d4..f64f61a 100644 --- a/week-1/2-mandatory/2-logic-error.js +++ b/week-1/2-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 getWordLength(word) { - return "word".length() + return word.length; } function multiply(a, b, c) { - a * b * c; - return; + + return a * b * c; } /* ======= TESTS - DO NOT MODIFY ===== From 01f6bf68ff8db3c33fda55d4616eeed5f96e7955 Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 20 Jun 2020 01:16:17 +0100 Subject: [PATCH 20/21] function output error corrected --- week-1/2-mandatory/3-function-output.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/week-1/2-mandatory/3-function-output.js b/week-1/2-mandatory/3-function-output.js index bbb88a2..0231107 100644 --- a/week-1/2-mandatory/3-function-output.js +++ b/week-1/2-mandatory/3-function-output.js @@ -1,16 +1,18 @@ // Add comments to explain what this function does. You're meant to use Google! function getNumber() { - return Math.random() * 10; + return Math.random() * 10; // returns a random integer from 0 to 9 + } // Add comments to explain what this function does. You're meant to use Google! function s(w1, w2) { - return w1.concat(w2); + return w1.concat(w2); // concatenates w1(string 1) with w2(string 2) } 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 to expect in return + return firstWord +" " + secondWord +" "+ thirdWord; } /* ======= TESTS - DO NOT MODIFY ===== From 3bf68ab00c8874657156e892fd590356ff41e6c6 Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 20 Jun 2020 01:36:51 +0100 Subject: [PATCH 21/21] tax calcultated --- week-1/2-mandatory/4-tax.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/week-1/2-mandatory/4-tax.js b/week-1/2-mandatory/4-tax.js index 6b84208..b61c6b4 100644 --- a/week-1/2-mandatory/4-tax.js +++ b/week-1/2-mandatory/4-tax.js @@ -5,7 +5,12 @@ Sales tax is 20% of the price of the product */ -function calculateSalesTax() {} +function calculateSalesTax(productPrice) { + + var salesTax = 0.2 * productPrice; + return productPrice+salesTax; + +} /* CURRENCY FORMATTING @@ -17,7 +22,11 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function formatCurrency() {} +function formatCurrency(price) { + var totPrice = calculateSalesTax(price); + totPrice = totPrice.toFixed(2); + return "£"+totPrice; +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working.