From 41ef8521f45b6301eb5710324a6b9adf80933289 Mon Sep 17 00:00:00 2001 From: Adeline Date: Sat, 23 Jan 2021 07:15:10 +0200 Subject: [PATCH 1/3] Added variables and strings +concatination --- exercises/C-variables/exercise.js | 1 + exercises/D-strings/exercise.js | 2 +- exercises/E-strings-concatenation/exercise.js | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..3a1735eb8 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,4 @@ // Start by creating a variable `greeting` +let greeting="Hello World"; console.log(greeting); diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..02597b7b6 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,3 @@ // Start by creating a variable `message` - +var message="This is a string"; console.log(message); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..9240afb03 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` - +var message="Hello my name is "; +message += "Adeline"; console.log(message); From 0556884deb834f3ab9c1442ef2b87667a7b726ed Mon Sep 17 00:00:00 2001 From: Adeline Date: Sat, 23 Jan 2021 10:47:58 +0200 Subject: [PATCH 2/3] added floats,sting methods and function parameters --- exercises/F-strings-methods/exercise.js | 3 ++- exercises/F-strings-methods/exercise2.js | 2 +- exercises/G-numbers/exercise.js | 4 ++++ exercises/I-floats/exercise.js | 4 ++++ exercises/J-functions/exercise.js | 1 + exercises/J-functions/exercise2.js | 1 + exercises/K-functions-parameters/exercise.js | 1 + exercises/K-functions-parameters/exercise2.js | 4 +++- exercises/K-functions-parameters/exercise3.js | 4 +++- exercises/K-functions-parameters/exercise4.js | 5 ++++- exercises/K-functions-parameters/exercise5.js | 4 +++- 11 files changed, 27 insertions(+), 6 deletions(-) diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..cb4868669 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` - +const name= "Adeline"; +let message=`My name is Adeline and my name is ${name.length} character log`; console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..2f3ab6b7e 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,3 @@ const name = " Daniel "; - +let message=`My name is ${name.trim()} and my name is ${name.length} characters long`; console.log(message); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..22ddffef3 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,5 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +let numberOfStudents=15; +let numberOfMentors=8; +let totalNumber=numberOfStudents+numberOfMentors; +console.log(totalNumber); \ No newline at end of file diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..96de8950b 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,6 @@ var numberOfStudents = 15; var numberOfMentors = 8; +numberOfStudents*=100/23; // for student +numberOfMentors*=100/23; // for mentor +console.log(Math.round(numberOfStudents)+"%"); +console.log(Math.round(numberOfMentors)+"%"); \ No newline at end of file diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..0fc4c3655 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,5 +1,6 @@ function halve(number) { // complete the function here + return number / 2; } var result = halve(12); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..d29e195d9 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,5 +1,6 @@ function triple(number) { // complete function here + return number * 3 } var result = triple(12); diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..00eecff14 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,6 +1,7 @@ // Complete the function so that it takes input parameters function multiply() { // Calculate the result of the function and return it + return num1 * num2; } // Assign the result of calling the function the variable `result` diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..e01c809fe 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,7 @@ // Declare your function first - +function divide(num1,num2){ + return num1 / num2; +} var result = divide(3, 4); console.log(result); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..68a39c188 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,7 @@ // Write your function here - +function createGreeting(string){ + return `Hello, my name is ${string}` +} var greeting = createGreeting("Daniel"); console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..a2c848adb 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,8 @@ // Declare your function first - +function addNumber(num1,num2){ + return num1 + num2; +} // Call the function and assign to a variable `sum` +let sum=addNumber('13',1+2+4); console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..f72ae72ed 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,7 @@ // 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); console.log(greeting); From ce2a4b38f7ded1ecc5b32d0da33a3ca7e2b2e89b Mon Sep 17 00:00:00 2001 From: Adeline Date: Sat, 23 Jan 2021 11:13:43 +0200 Subject: [PATCH 3/3] fixed syntax errorrs,logic errors --- exercises/L-functions-nested/exercise.js | 13 +++++++++++++ mandatory/1-syntax-errors.js | 16 +++++++++------- mandatory/2-logic-error.js | 12 ++++++++---- mandatory/3-function-output.js | 3 +++ mandatory/4-tax.js | 9 +++++++-- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..6912c8a78 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,16 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + + +function namesInUpperCase(names){ + return names.toUpperCase(); +} +function shoutyGreeting(names){ + return "hello".toUpperCase() +" "+ namesInUpperCase(names); +} +console.log(shoutyGreeting(mentor1)); +console.log(shoutyGreeting(mentor2)); +console.log(shoutyGreeting(mentor3)); +console.log(shoutyGreeting(mentor4)); +console.log(shoutyGreeting(mentor5)); diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index 0a21afd1b..a56d154db 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,18 +1,20 @@ // 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; } +console.log(addNumbers(3, 4, 6), 13); -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("Sonjide", 27)); function getTotal(a, b) { - total = a ++ b; - - return "The total is total" + total = a + b; + return "The total is"+" "+ total; } - +console.log(getTotal(23, 5)); /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 3c578ad87..c2891d095 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,17 +1,21 @@ // 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(); } +console.log(trimWord("codeYourFuture")); function getWordLength(word) { - return "word".length(); + return word.length; } +console.log(getWordLength("A wild sentence appeared!")); function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; } +console.log(multiply(2, 3, 6)); + + /* =================================================== diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index c9221a200..239d1ab8a 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,9 +1,11 @@ // Add comments to explain what this function does. You're meant to use Google! +//In JavaScript, to get a random number between 0 and 1, use the Math. random() function. If you want a random number between 1 and 10, multiply the results of Math. random by 10, then round up or down. function getNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! +//So concat() is a method uses in javaScript that join two or more strings and return a new string function s(w1, w2) { return w1.concat(w2); } @@ -11,6 +13,7 @@ function s(w1, w2) { 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+ " "+ secondWord + " "+thirdWord; } /* diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index c9e41c691..1645a1610 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,9 @@ Sales tax is 20% of the price of the product */ -function calculateSalesTax() {} +function calculateSalesTax(priceOfProduct) { + const saleTax= priceOfProduct + (20 / 100) * priceOfProduct; // calculate the saletax which is 20 % -- 20/100 + return saleTax; /* CURRENCY FORMATTING @@ -17,7 +19,10 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(credit) { + const creditAmount= calculateSalesTax(credit).toFixed(2); //this round off to two decimal place + return `£${creditAmount}`; } + /* ===================================================