diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..1c960d355 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,4 @@ -console.log("Hello world"); +console.log("Hello World. I just started learning JavaScript!."); +console.log("I like playing piano."); +console.log(2 + 2); + diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..7a449fb32 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,7 @@ // Start by creating a variable `greeting` +let greeting = "Hello world"; console.log(greeting); +console.log(greeting); +console.log(greeting); + diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..c0610b025 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,7 @@ // Start by creating a variable `message` +let message = "This is a string"; +let messageType = typeof message; console.log(message); +console.log(messageType); + diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..e447926f3 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +let greetingStart = " Hello my name is "; +let name = "Ntshumayelo"; -console.log(message); +let greeting = greetingStart + name; +console.log(greeting); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..ce7a8441c 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +let name = "Ntshumayelo"; +let message = "My name is Ntshumayelo"; -console.log(message); +console.log(nameLength); + \ No newline at end of file diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..2fda01a20 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,5 @@ -const name = " Daniel "; - +const name = "Daniel"; +let lengthName = name.length +let message = "my name is " + name.trim() + " and my name is " + lengthName + " characters long"; console.log(message); +//console.log(name.trim); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..b681054ba 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,13 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +let numberOfStudents = 15 +let numberOfMentors = 8 +let totalNumberOfStudentsMentors = numberOfStudents + numberOfMentors; + +let percentageOfStudents = numberOfStudents * 100 /totalNumberOfStudentsMentors; +percentageOfStudents = Math.round(percentageOfStudents); +console.log("Percentage of Students: " + percentageOfStudents + "%"); + + +let percentageOfMentors = numberOfMentors * 100 /totalNumberOfStudentsMentors; +percentageOfMentors = Math.round(percentageOfMentors); +console.log("Percentage of Mentors: " + percentageOfMentors + "%"); \ No newline at end of file diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..175c40aff 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,9 @@ function halve(number) { + let result = number / 2; + return result; // complete the function here } -var result = halve(12); +let result = halve(12); console.log(result); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..75d1c2f90 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,4 +1,5 @@ function triple(number) { + return number * 3; // complete function here } diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..89a6715df 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,5 +1,7 @@ // Complete the function so that it takes input parameters -function multiply() { +function multiply(num1, num2) { + let result = num1 * num2; + return result; // Calculate the result of the function and return it } diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..4d84416f3 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,8 @@ // Declare your function first - +function divide(num1, num2){ +let result = num1 / num2; +return result; +} 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..a6ac13c76 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,8 @@ // Write your function here - -var greeting = createGreeting("Daniel"); +function createGreeting(name){ +let greeting = "Hello, My name is ${name}" +return greeting; +} +let greeting = createGreeting("Daniel"); console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..2fddf9390 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,8 @@ // Declare your function first - +function sumNumbers(num1, num2){ + let result = num1 + num2; + return result; +} // Call the function and assign to a variable `sum` - +let sum = sumNumbers(13,124) console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..9256e0619 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,8 @@ // Declare your function here - +function createLongGreeting(name, age){ + let greeting = "Hello, my name is ${name} and I'm ${age} old" + return greeting; +} const greeting = createLongGreeting("Daniel", 30); console.log(greeting); diff --git a/exercises/L-functions-nested/README.md b/exercises/L-functions-nested/README.md index 1c4ae9c8a..edeae7ffd 100644 --- a/exercises/L-functions-nested/README.md +++ b/exercises/L-functions-nested/README.md @@ -28,7 +28,7 @@ function createCreeting(name, age) { ``` HELLO DANIEL HELLO IRINA -HELLO MIMI +HELLO MIMIv HELLO ROB HELLO YOHANNES ``` diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..f4096e7a5 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,22 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +let mentor1 = "Daniel"; +let mentor2 = "Irina"; +let mentor3 = "Mimi"; +let mentor4 = "Rob"; +let mentor5 = "Yohannes"; + +function spellName(name) { + return name.toUpperCase(); + } +function shoutyGreeting(name){ + let message = 'HELLO '+ spellName(name); + return message +}; +console.log(shoutyGreeting(mentor1)); +console.log(shoutyGreeting(mentor2)); +console.log(shoutyGreeting(mentor3)); +console.log(shoutyGreeting(mentor4)); +console.log(shoutyGreeting(mentor5)); \ No newline at end of file diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..2e1fd877c 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,16 +1,17 @@ // 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 getTotal(a, b) { - total = a ++ b; + total = a + b; - return "The total is total"; + return "The total is " + total; } /* diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..9d1dc284f 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(); } 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..671f1c73c 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! +//returns a random number between 0 (inclusive) and 1 (exclusive) and multiplies with 10 function getRandomNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! +// This function combines typed array with the new array. function combine2Words(word1, word2) { return word1.concat(word2); } diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..779402efb 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,10 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +function calculateSalesTax(priceOfProduct) { + let percentageOfProduct = (priceOfProduct) * 0.2; + return percentageOfProduct + (priceOfProduct); +} /* CURRENCY FORMATTING @@ -17,7 +20,10 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(num) { +let priceWithSalesTax = calculateSalesTax(num); +return "£" + priceWithSalesTax.toFixed(2); +} /* ===================================================