diff --git a/week-1/1-exercises/B-hello-world/exercise.js b/week-1/1-exercises/B-hello-world/exercise.js index b179ee9..4a05819 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("Java is fun"); \ No newline at end of file diff --git a/week-1/1-exercises/C-variables/README.md b/week-1/1-exercises/C-variables/README.md index 26eccc1..5230e5c 100644 --- a/week-1/1-exercises/C-variables/README.md +++ b/week-1/1-exercises/C-variables/README.md @@ -15,7 +15,7 @@ The program above will print "Hello world" to the console. Notice how it uses th * Add a variable `greeting` to exercise.js (make sure it comes _before_ the console.log) * Print your `greeting` to the console 3 times -> Remember: to run this exercise you must change directory to the `D-variables`. If you already have a terminal window open for the previous exercise you can do this by running the command `cd ../D-variables`. +> Remember: to run this exercise you must change directory to the `cd D-variables`. If you already have a terminal window open for the previous exercise you can do this by running the command `cd ../D-variables`. ## Expected result diff --git a/week-1/1-exercises/C-variables/exercise.js b/week-1/1-exercises/C-variables/exercise.js index a6bbb97..c06ad85 100644 --- a/week-1/1-exercises/C-variables/exercise.js +++ b/week-1/1-exercises/C-variables/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `greeting` +let greeting ="Hello world" console.log(greeting); +console.log(greeting); +console.log(greeting); diff --git a/week-1/1-exercises/D-strings/exercise.js b/week-1/1-exercises/D-strings/exercise.js index 2cffa6a..37c19ad 100644 --- a/week-1/1-exercises/D-strings/exercise.js +++ b/week-1/1-exercises/D-strings/exercise.js @@ -1,3 +1,7 @@ // Start by creating a variable `message` +let message = "Some string"; +let messagetype = typeof message; console.log(message); +console.log(messagetype); + diff --git a/week-1/1-exercises/E-strings-concatenation/exercise.js b/week-1/1-exercises/E-strings-concatenation/exercise.js index 2cffa6a..23cc2b6 100644 --- a/week-1/1-exercises/E-strings-concatenation/exercise.js +++ b/week-1/1-exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +var greeting = 'Hello, my name is '; +var firstName = 'Hussein'; +var intro = greeting + firstName -console.log(message); +console.log(intro); diff --git a/week-1/1-exercises/F-strings-methods/exercise.js b/week-1/1-exercises/F-strings-methods/exercise.js index 2cffa6a..2be79f8 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 = "Hussein"; +var namelength = name.length; +console.log("My name is Hussein and my name is " + name.length + " characters long" ); + -console.log(message); diff --git a/week-1/1-exercises/F-strings-methods/exercise2.js b/week-1/1-exercises/F-strings-methods/exercise2.js index b4b4694..d95cf78 100644 --- a/week-1/1-exercises/F-strings-methods/exercise2.js +++ b/week-1/1-exercises/F-strings-methods/exercise2.js @@ -1,3 +1,4 @@ -const name = " Daniel "; - -console.log(message); +const name = " Hussein"; +var namelength = name.length; +var message = "My name is Hussein and my name is " + name.length + " characters long"; +console.log(message.trim() ); diff --git a/week-1/1-exercises/G-numbers/exercise.js b/week-1/1-exercises/G-numbers/exercise.js index 49e7bc0..66a4ecb 100644 --- a/week-1/1-exercises/G-numbers/exercise.js +++ b/week-1/1-exercises/G-numbers/exercise.js @@ -1 +1,8 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +var numberOfStudents = 15; +var numberOfMentors = 8; +var sum = numberOfStudents + numberOfMentors; +console.log("Number of students: " + numberOfStudents); +console.log("Number of mentors: " + numberOfMentors); +console.log("Total numnber of students and mentors: " + sum); + diff --git a/week-1/1-exercises/I-floats/exercise.js b/week-1/1-exercises/I-floats/exercise.js index a5bbcd8..5106afb 100644 --- a/week-1/1-exercises/I-floats/exercise.js +++ b/week-1/1-exercises/I-floats/exercise.js @@ -1,2 +1,8 @@ var numberOfStudents = 15; var numberOfMentors = 8; +var sum = numberOfStudents + numberOfMentors; +var studentPercentage = Math.round((numberOfStudents/sum) * 100); +var mentorsPercentage = Math.round((numberOfMentors/sum) * 100); + +console.log("Percentage students: " + studentPercentage + "%"); +console.log("Percentage mentors: " + mentorsPercentage + "%"); diff --git a/week-1/1-exercises/J-functions/exercise.js b/week-1/1-exercises/J-functions/exercise.js index 0ae5850..a62cdfb 100644 --- a/week-1/1-exercises/J-functions/exercise.js +++ b/week-1/1-exercises/J-functions/exercise.js @@ -1,5 +1,5 @@ function halve(number) { - // complete the function here + return number/2 } var result = halve(12); diff --git a/week-1/1-exercises/J-functions/exercise2.js b/week-1/1-exercises/J-functions/exercise2.js index 82ef5e7..a70b80b 100644 --- a/week-1/1-exercises/J-functions/exercise2.js +++ b/week-1/1-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/week-1/1-exercises/K-functions-parameters/exercise.js b/week-1/1-exercises/K-functions-parameters/exercise.js index 8d5db5e..62e7148 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise.js +++ b/week-1/1-exercises/K-functions-parameters/exercise.js @@ -1,6 +1,6 @@ // 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` diff --git a/week-1/1-exercises/K-functions-parameters/exercise2.js b/week-1/1-exercises/K-functions-parameters/exercise2.js index db7a890..8b522f6 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise2.js +++ b/week-1/1-exercises/K-functions-parameters/exercise2.js @@ -1,4 +1,7 @@ // Declare your function first +function divide(a,b){ + return a / b; +} var result = divide(3, 4); diff --git a/week-1/1-exercises/K-functions-parameters/exercise3.js b/week-1/1-exercises/K-functions-parameters/exercise3.js index 537e9f4..de0c53a 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise3.js +++ b/week-1/1-exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,8 @@ // Write your function here +function createGreeting(name){ + return "Hello, my name is " + name; +} -var greeting = createGreeting("Daniel"); +var greeting = createGreeting("Hussein"); console.log(greeting); diff --git a/week-1/1-exercises/K-functions-parameters/exercise4.js b/week-1/1-exercises/K-functions-parameters/exercise4.js index 7ab4458..acac982 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise4.js +++ b/week-1/1-exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,8 @@ // Declare your function first - +function addation(a,b){ + return a + b; +} +var sum = addation(13,124); // Call the function and assign to a variable `sum` console.log(sum); diff --git a/week-1/1-exercises/K-functions-parameters/exercise5.js b/week-1/1-exercises/K-functions-parameters/exercise5.js index 7c5bcd6..881359d 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise5.js +++ b/week-1/1-exercises/K-functions-parameters/exercise5.js @@ -1,5 +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); +const greeting = createLongGreeting("Hussein", 30); console.log(greeting); diff --git a/week-1/1-exercises/L-functions-nested/exercise.js b/week-1/1-exercises/L-functions-nested/exercise.js index a5d3774..f8b03c0 100644 --- a/week-1/1-exercises/L-functions-nested/exercise.js +++ b/week-1/1-exercises/L-functions-nested/exercise.js @@ -1,5 +1,22 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; + +//Calculating the percentage of students +function percentStdts(numOfStudents){ + return Math.round(numOfStudents / 23 * 100); +} +function message(numOfStudents){ + var value = percentStdts(numOfStudents); + return "Percentage of students: " + value + "%"; +} +console.log(message(15)); + + //Calculating the percentage of mentors +function percentMentors(numOfMentors){ + return Math.round(numOfMentors / 23 * 100); +} +function mentorsMessage(numOfMentors){ + var mentorsValue = percentMentors(numOfMentors); + return "Percentage of students: " + mentorsValue + "%"; +} +console.log(mentorsMessage(8)); + + diff --git a/week-1/2-mandatory/1-syntax-errors.js b/week-1/2-mandatory/1-syntax-errors.js index 6910f28..7c408ae 100644 --- a/week-1/2-mandatory/1-syntax-errors.js +++ b/week-1/2-mandatory/1-syntax-errors.js @@ -2,19 +2,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; } -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) { + var remainder = a % b; - // Use string interpolation here - return "The total is %{total}" -} + + return `The remainder is ${remainder}`; + } /* ======= TESTS - DO NOT MODIFY ===== */ // diff --git a/week-1/2-mandatory/2-logic-error.js b/week-1/2-mandatory/2-logic-error.js index 1e0a9d4..abe2cf9 100644 --- a/week-1/2-mandatory/2-logic-error.js +++ b/week-1/2-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 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 ===== diff --git a/week-1/2-mandatory/3-function-output.js b/week-1/2-mandatory/3-function-output.js index bbb88a2..5ba717e 100644 --- a/week-1/2-mandatory/3-function-output.js +++ b/week-1/2-mandatory/3-function-output.js @@ -1,14 +1,23 @@ // Add comments to explain what this function does. You're meant to use Google! + +/* This is a random numbers generating function that give a random number between + 0 and 9 (both included). */ function getNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! + +/* This is a method used to combine arrays into one array. The array before concat() (w1) will be placed first in the +new array. And the array inside the parenthesis (w2) will be placed last. */ function s(w1, w2) { return w1.concat(w2); } function concatenate(firstWord, secondWord, thirdWord) { + + return `${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 } diff --git a/week-1/2-mandatory/4-tax.js b/week-1/2-mandatory/4-tax.js index 6b84208..f92580f 100644 --- a/week-1/2-mandatory/4-tax.js +++ b/week-1/2-mandatory/4-tax.js @@ -5,7 +5,11 @@ Sales tax is 20% of the price of the product */ -function calculateSalesTax() {} +function calculateSalesTax(price) { + var priceAfterTax = (price * 0.2) + price; + return priceAfterTax; + +} /* CURRENCY FORMATTING @@ -17,7 +21,10 @@ 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 finalPrice = calculateSalesTax(price); + return `£${finalPrice.toFixed(2)}` +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. diff --git a/week-1/3-extra/1-currency-conversion.js b/week-1/3-extra/1-currency-conversion.js index 7f321d9..fa4bb3b 100644 --- a/week-1/3-extra/1-currency-conversion.js +++ b/week-1/3-extra/1-currency-conversion.js @@ -5,7 +5,9 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(pounds) { + return pounds * 1.4; +} /* CURRENCY FORMATTING @@ -16,7 +18,9 @@ function convertToUSD() {} Find a way to add 1% to all currency conversions (think about the DRY principle) */ -function convertToBRL() {} +function convertToBRL(pound) { + return (pound * 5.7) * 1.01; +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. diff --git a/week-1/3-extra/2-piping.js b/week-1/3-extra/2-piping.js index 93c0bf7..52d2995 100644 --- a/week-1/3-extra/2-piping.js +++ b/week-1/3-extra/2-piping.js @@ -16,22 +16,25 @@ the final result to the variable goodCode */ -function add() { - +function add(a, b) { +return a + b; } -function multiply() { - +function multiply(c, d) { +return c * d; } -function format() { - +function format(num) { +return `£${num}`; } -const startingValue = 2 +const startingValue = 2; + // Why can this code be seen as bad practice? Comment your answer. -let badCode = +let badCode = format(multiply(add(startingValue, 10), 2)); + + /* BETTER PRACTICE */