diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..2221c2dba 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` +let greetingStart = "Hello my name is "; +let firstName = "Rabie "; -console.log(message); +console.log(greetingStart + firstName); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..d4bb67235 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,11 @@ -// Start by creating a variable `message` +let firstMessage = "Hello my name is "; +let secondmessage = "and my name is "; +let thirdmessage = " long"; +let name = "Rabie "; +let length = name.length; + + +let message = firstMessage + name + secondmessage + length + thirdmessage; + console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..d4bb67235 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,11 @@ -const name = " Daniel "; +let firstMessage = "Hello my name is "; +let secondmessage = "and my name is "; +let thirdmessage = " long"; +let name = "Rabie "; +let length = name.length; + + +let message = firstMessage + name + secondmessage + length + thirdmessage; + console.log(message); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..129797002 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,7 @@ -// Start by creating a variables `numberOfStudents` and `numberOfMentors` +let numOfStudents = 15; +let numOfmentores = 8; +let total = numOfStudents + numOfmentores; + +console.log("Number of student: " + numOfStudents); +console.log("Number of mentores: " + numOfmentores); +console.log("Total number of students and mentores " + total); diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..9af54fea6 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,9 @@ -var numberOfStudents = 15; -var numberOfMentors = 8; +let numOfStudents = 15; +let numOfmentores = 8; +let total = numOfStudents + numOfmentores; + +let percentageOfStudents = (numOfStudents / total) * 100; +let percentageOfMentores = (numOfmentores / total) * 100; + +console.log("Percentage Students: " + Math.round(percentageOfStudents) + "%"); +console.log("Percentage Mentores: " + Math.round (percentageOfMentores) + "%"); diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..d5b9b5740 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,8 @@ function halve(number) { - // complete the function here + return number/2; } var result = halve(12); console.log(result); + diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..ca499a8ab 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,5 +1,5 @@ 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..9ccf2952a 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,9 +1,7 @@ -// Complete the function so that it takes input parameters -function multiply() { - // Calculate the result of the function and return it +function multiply(a, b){ + return a * b; } -// Assign the result of calling the function the variable `result` -var result = multiply(3, 4); +let result = multiply(5, 3); console.log(result); diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..5d3d39c6f 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(a, b){ + return a / b; +} -var result = divide(3, 4); +let result = divide(9, 3); console.log(result); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..f8cbe7fc1 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){ + console.log("Hello, my name is " + name); + return name; +} -var greeting = createGreeting("Daniel"); +let greeting = createGreeting("Rabie"); console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..48f3144ea 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,8 @@ -// Declare your function first +function summation(num1, num2){ + let sum = num1 + num2; + return sum +} -// Call the function and assign to a variable `sum` +let result = summation(13, 124); -console.log(sum); +console.log(result); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..7a6a5f48e 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,7 @@ -// Declare your function here +function greeting(name, age){ + let message = "Hello, my name is " + name + " and I am " + age + " years old"; + return message; +} -const greeting = createLongGreeting("Daniel", 30); - -console.log(greeting); +let greetingMessage = greeting("Rabie", 27); +console.log(greetingMessage); diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..bd5b0e3f2 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,18 +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) { //There are missing "," between each argument. 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"; // after name there needs to be + also after the string. +} function getTotal(a, b) { - total = a ++ b; + let total = a + b; - return "The total is total"; + return "The total is " + total; } + /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..82e864c5d 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(); // wordtrim is undefined word. } function getStringLength(word) { - return "word".length(); + return word.length; // word shouldn't be a string. } function multiply(a, b, c) { - a * b * c; - return; + + return a * b * c; // the return should have the multiplication like: return a * b * c; } /* diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..299307741 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -11,6 +11,7 @@ function combine2Words(word1, 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 + " " + secondWord + " " + thirdWord; } /* diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..d488aa012 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(priceBeforeTax) { + return priceBeforeTax + (priceBeforeTax * 0.2); +} /* 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(priceBeforeTax) { + let priceAfterTax = calculateSalesTax(priceBeforeTax); + return `£${priceAfterTax.toFixed(2)}`; +} /* ===================================================