diff --git a/README.md b/README.md index 5833a402f..2e6079265 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Like learning a musical instrument, programming requires daily practise. -The exercises are split into three folders: `exercises`, `mandatory` and `extra`. All homework in the `exercise` and `mandatory` section **must** be completed for homework by the following lesson. +The exercises are split into three folders: `exercises`, `mandatory` and `extra`. All homework in the `exercise` and `mandatory` section **must** be completed for homework by the following lesson. The `extra` folder contains exercises that you can complete to challenge yourself, but are not required for the following lesson. diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..227aeb005 100644 --- a/exercises/D-strings/exercise.js +++ b/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(message); +console.log(messageType); // logs 'string' diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..d6e551de2 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` -console.log(message); +const message = "Hello, my name is "; +const name = "Georgina"; +console.log(message + name); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..58e14bd84 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,16 @@ // Start by creating a variable `message` +// const myName = "Georgina"; +// var nameLength = Georgina.length; + +// console.log(nameLength); // Logs 8 + + + + const myName = "Georgina "; + console.log( + `My name is ${myName}, the length of my name is ${myName.length} characters` + ); +console.log(); + + -console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..931a25694 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,13 @@ -const name = " Daniel "; +// const name = " Georgina "; -console.log(message); +// console.log( +// `My name is ${Name}, the length of my name is ${Name.length} characters` +// ); + +// console.log(message); +const name = " Georgina "; +console.log( + `My name is ${name.trim()}, the length of my name is ${ + name.trim().length + } characters` +); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..5571fa962 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,7 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +const numberOfStudents = "15"; +const numberOfMentors = "8"; + +const sum = 15 + 8; // 23 + +console.log(sum); diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..e293065cd 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,21 @@ -var numberOfStudents = 15; -var numberOfMentors = 8; +const numberOfStudents = 15; +const numberOfMentors = 8; +const sum = numberOfStudents + numberOfMentors; + +// console.log (TotalnumberOfStudents ${numberOfStudents} ); + +// console.log (TotalnumberOfMentors ${numberOfMentors } ); + +//console.log (TotalNumber ${totalNumber} ); + +const percentageStudents = (numberOfStudents/sum) * 100;//65 + +console.log (percentageStudents) + +const percentageMentors = (numberOfMentors/sum) * 100;//34.7 (math.round =35 + +console.log (percentageMentors) + + + + diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..c98e4737f 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,16 @@ function halve(number) { // complete the function here + + return number /2; } var result = halve(12); -console.log(result); +console.log(result);//6 + +var result = halve(10); +console.log (result); //5 + +var result = halve(100); +console.log (result); //50 + diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..36d52ef48 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,7 +1,8 @@ function triple(number) { // complete function here + return number * 3; } var result = triple(12); -console.log(result); +console.log(result); //36 diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..36cf19f47 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 (numberOne, numberTwo) { + // Calculate the result of the function and return it + return numberOne * numberTwo; } // Assign the result of calling the function the variable `result` -var result = multiply(3, 4); +var result = multiply(3, 4);//12 console.log(result); diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..e11abbcc8 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,6 @@ // Declare your function first - +function divide(numberOne, numberTwo) { + return numberOne / numberTwo; +} 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..11ac63998 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,9 @@ // Write your function here +function greeting(greetingStart, name) {} +//var greeting = createGreeting("Daniel"); +var greetingStart = "Hello, my name is "; +var name = "Georgina"; -var greeting = createGreeting("Daniel"); +greeting = greetingStart + name; -console.log(greeting); +console.log(greeting); // Logs "Hello, my name is Georgina" diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..1897c5cff 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,8 @@ // Declare your function first - +function addition(numberOne, numberTwo) { + return numberOne + numberTwo; +} // Call the function and assign to a variable `sum` +const sum = addition(13, 124); console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..1d57b4da5 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,10 @@ // Declare your function here +//function greeting(greetingStart, name, age) { +function createLongGreeting(name, age) { + return `Hello, my name is ${name} and I'm ${age} years old`; +} -const greeting = createLongGreeting("Daniel", 30); +//var greeting = createGreeting("Georgina"); +const greeting = createLongGreeting("Georgina", 43); console.log(greeting); diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..33763325c 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,23 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +var mentor3 = "Mimi"; +var mentor4 = "Rob"; +var mentor5 = "Yohannes"; + +function CreateGreeting(name) { + return `HELLO ${name}`; +} + +function ToUpper(string) { + return CreateGreeting(string.toUpperCase()); +} + +console.log(ToUpper(mentor1)); +console.log(ToUpper(mentor2)); +console.log(ToUpper(mentor3)); +console.log(ToUpper(mentor4)); +console.log(ToUpper(mentor5)); + +console.log("\n"); diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..ef331ca2a 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,18 +1,24 @@ // 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; } +addNumbers(3, 4, 6); + +function introduceMe(name, age) { + return "Hello, my name is " + name + " and I am " + age + "years old"; +} +introduceMe("Sonjid", 27); -function introduceMe(name, age) - return "Hello, my name is " + name "and I am " age + "years old"; function getTotal(a, b) { - total = a ++ b; + total = a + b; - return "The total is total"; + return "The total is " + total; } +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 9cca7603b..37c4ebc15 100644 --- a/mandatory/2-logic-error.js +++ b/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 getStringLength(word) { - return "word".length(); + return word.length; } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; } /* diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..36ff46a8f 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,16 +1,35 @@ // Add comments to explain what this function does. You're meant to use Google! +//This function generates a random decimal value between 0 and 1 function getRandomNumber() { - return Math.random() * 10; + return Math.random() * 10; //The Math.random() function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1) with approximately uniform distribution over that range } // Add comments to explain what this function does. You're meant to use Google! function combine2Words(word1, word2) { return word1.concat(word2); + return word1.concat(word2); //to join two or more text strings into one string } 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, " ", thirdWord); +} + +/* + +} + +// Add comments to explain what this function does. You're meant to use Google! +//This function is used to join two strings +function combine2Words(word1, word2) { + return word1.concat(word2); +} + +function concatenate(firstWord, secondWord, thirdWord) { + return firstWord.concat(" ", 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. } /* diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..6748243dd 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -18,6 +18,15 @@ function calculateSalesTax() {} */ function addTaxAndFormatCurrency() {} +function calculateSalesTax(beforeSalesTax) { + // return the total price then multiply by tax percentage + return beforeSalesTax + beforeSalesTax * 0.2; +} + +function addTaxAndFormatCurrency(numberToFormat) { + // returns: total price + tax using £ as the start currency symbol. Price has 2 decimal places at the end via .toFixed() + return `£${(numberToFormat + numberToFormat * 0.2).toFixed(2)}`; +} /* ===================================================