diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..745f0a5a0 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,6 @@ console.log("Hello world"); + +console.log (12345); +console.log ("Hello World I just started learning Jvascript"); + + diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..0fdd177dc 100644 --- a/exercises/C-variables/exercise.js +++ b/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/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..d4da48084 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 in Javascript"; +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..743f1b6a1 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,8 @@ // Start by creating a variable `message` +var greetingStart = "Hello, my name is "; +var name = "Karleen"; +var greetingEnd = ", I'm glad you visited." -console.log(message); +var greeting = greetingStart + name + greetingEnd; + +console.log(greeting); diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..800d9eee3 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,15 @@ var numberOfStudents = 15; var numberOfMentors = 8; + +const amtOfTrainees = "Number of trainees: "; +const numberOfTrainees = 36; + +console.log (amtOfTrainees + numberOfTrainees); + +const amtOfMentors = "Number of mentors: "; +const numberOfMentors = 10; + +console.log (amtOfMentors + numberOfMentors); + +const sum = 36 + 10; +console.log ("Total number of trainees and mentors: " + sum); \ No newline at end of file diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..edab3cb27 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,13 @@ -function halve(number) { - // complete the function here + +function increaseByHalf(number) { + return number / 2 + number } -var result = halve(12); +var result = increaseByHalf(400); +console.log(result); +var result = increaseByHalf(1000); console.log(result); + +var result = increaseByHalf(8500); +console.log(result); \ No newline at end of file diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 75b3c6aab..8247214b9 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,7 +5,12 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(number) { + return number * 1.4; +} + +console.log(convertToUSD(32)); +console.log(convertToUSD(50)); /* CURRENCY CONVERSION @@ -15,7 +20,13 @@ function convertToUSD() {} They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL. */ -function convertToBRL() {} +function convertToBRL(a) { + a = (a * (99 / 100 * 5.7)).toFixed(2); + return +a; +} + +console.log(convertToBRL(30)); +console.log(convertToBRL(1.50)); /* ======= 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/extra/2-piping.js b/extra/2-piping.js index b4f8c4c1b..38859c5a9 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -16,26 +16,41 @@ the final result to the variable goodCode */ -function add() { - +function add(a,b) { + return (a + b).toFixed(1); } -function multiply() { +console.log(add(1,3)); +console.log(add(2.4,5)) +function multiply(c,d) { + return c * d; } -function format() { +console.log(multiply(2,3)) +function format(str) { + return "£" + str; } -const startingValue = 2; +console.log(format(16)); +console.log(format(10.1)); +const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = +//It is bad practice because the code is difficult to understand and read. +let badCode = format(multiply(add(startingValue,10),2)); + +console.log(badCode); + + /* BETTER PRACTICE */ +let first = startingValue + 10; +let second = first * 2; +let goodCode = format(second); -let goodCode = +console.log(goodCode); /* ======= 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/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..d9dcc6ab7 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,16 +1,16 @@ // 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; - - return "The total is total"; + const total = a + b; + return "The total is " + total; } /* diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..a7235f9bb 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..a22f84a84 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -2,13 +2,16 @@ function getRandomNumber() { return Math.random() * 10; } +// The Math.random method returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1. // Add comments to explain what this function does. You're meant to use Google! function combine2Words(word1, word2) { return word1.concat(word2); } +//The .concat method joins two or more strings. 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..7e05a2df2 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,8 +5,13 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} - +function calculateSalesTax(a) { + + return (20 / 100 * a) + a; +} +console.log(calculateSalesTax(15)); +console.log(calculateSalesTax(17.50)); +console.log(calculateSalesTax(34)); /* CURRENCY FORMATTING =================== @@ -17,7 +22,12 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(b) { + return "£" + ((20 / 100 * b) + b).toFixed(2); +} +console.log(addTaxAndFormatCurrency(15)); +console.log(addTaxAndFormatCurrency(17.50)); +console.log(addTaxAndFormatCurrency(34)); /* ===================================================