From 9ee23d386d285473ff26db316118bb01d172a3cb Mon Sep 17 00:00:00 2001 From: Rebwar Date: Mon, 22 Aug 2022 16:30:22 +0100 Subject: [PATCH 1/7] solve all the chaleng except 3_magic-8-ball.js --- exercises/B-hello-world/exercise.js | 3 ++ exercises/C-variables/exercise.js | 10 +++++-- exercises/D-strings/exercise.js | 7 ++++- exercises/E-strings-concatenation/exercise.js | 3 ++ exercises/F-strings-methods/exercise.js | 5 ++++ exercises/F-strings-methods/exercise2.js | 17 +++++++++-- exercises/G-numbers/exercise.js | 5 ++++ exercises/I-floats/exercise.js | 23 +++++++++++++-- exercises/J-functions/exercise.js | 9 ++++-- exercises/J-functions/exercise2.js | 8 +++-- exercises/K-functions-parameters/exercise.js | 3 +- exercises/K-functions-parameters/exercise2.js | 5 +++- exercises/K-functions-parameters/exercise3.js | 3 ++ exercises/K-functions-parameters/exercise4.js | 4 +++ exercises/K-functions-parameters/exercise5.js | 4 ++- exercises/L-functions-nested/exercise.js | 29 +++++++++++++++---- extra/1-currency-conversion.js | 13 +++++++-- extra/2-piping.js | 20 +++++++------ extra/3-magic-8-ball.js | 19 ++++++++++-- mandatory/1-syntax-errors.js | 12 ++++---- mandatory/2-logic-error.js | 10 ++++--- mandatory/3-function-output.js | 5 ++++ mandatory/4-tax.js | 11 +++++-- 23 files changed, 181 insertions(+), 47 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..fe18d1a4e 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("Hello World!!! Just leave me alone!"); +console.log(4 ** 2); diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..6d7ae625d 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,9 @@ // Start by creating a variable `greeting` - -console.log(greeting); +let greeting = "Hello world!"; +console.log(greeting.repeat(3)); +greeting = ["Hello world!", "Hello world!", "Hello world!"]; +function repeat3Time(greeting) { + return greeting.map((str) => str); +} +const result = repeat3Time(greeting); +console.log(...result); diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..6371e0dee 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,8 @@ // Start by creating a variable `message` - +function messageType(massage) { + return `This is a ${typeof massage} and type of ${typeof massage} is: ${typeof massage}`; +} +const message = messageType("Rebwar"); console.log(message); +console.log(messageType(5)); +console.log(messageType({})); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..7f4b40ef6 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` +const greetingStart = "Hello, my name is "; +const name = "Rebwar"; +const message = greetingStart + name; console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..d8c09d280 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,8 @@ // Start by creating a variable `message` +function lengthOfName(name) { + let trimeStr = name.replace(/\s/g, ""); + return `my name is ${name} and my name is ${trimeStr.length} characters long`; +} +const message = lengthOfName("Rebwar Azizi"); console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..4eabfa760 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,14 @@ -const name = " Daniel "; - -console.log(message); +function lengthTrim(name) { + let trimeStr = name.trim(); + return `my name is ${name} and my name is ${trimeStr.length} characters long`; +} +function lengthRegEx(name) { + let trimeStr = name.replace(/\s/g, ""); + return `my name is ${name} and my name is ${trimeStr.length} characters long`; +} +const nametrim = " Rebwar a "; +const nameReqEx = " Rebwar a "; +const messagetrim = lengthTrim(nametrim); +const messageRegEx = lengthRegEx(nameReqEx); +console.log(`length with trim(): ${messagetrim}`); +console.log(`length with RegExp: ${messageRegEx}`); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..c58efb4ae 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,6 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` + +const numberOfStudents = 15; +const numberOfMentors = 8; +const total = numberOfStudents + numberOfMentors; +console.log(`the total number of students and mentors are ${total}`); diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..61a1ad0fb 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; + +function percentageNumber(num1, num2, percentage) { + const sum = num1 + num2; + return Math.round((100 / sum) * percentage); +} + +const students = percentageNumber( + numberOfStudents, + numberOfMentors, + numberOfStudents +); + +const mentors = percentageNumber( + numberOfStudents, + numberOfMentors, + numberOfMentors +); +console.log(`Percentage students: ${students}%`); +console.log(`Percentage mentors: ${mentors}%`); diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..d25d80d5a 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,10 @@ function halve(number) { - // complete the function here + return number / 2; } -var result = halve(12); - +const result = halve(12); +const result1 = halve(100); +const result2 = halve(88); console.log(result); +console.log(result1); +console.log(result2); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..1e2a72f32 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,7 +1,11 @@ function triple(number) { - // complete function here + return number * 3; } -var result = triple(12); +const result = triple(12); +const result1 = triple(35); +const result2 = triple(50); console.log(result); +console.log(result1); +console.log(result2); diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..dbd50454d 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,6 +1,7 @@ // Complete the function so that it takes input parameters -function multiply() { +function multiply(a, b) { // Calculate the result of the function and return it + return a * b; } // Assign the result of calling the function the variable `result` diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..3554839c1 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(a, b) { + return a / b; +} -var result = divide(3, 4); +const 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..e928bd2de 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,4 +1,7 @@ // Write your function here +function createGreeting(name) { + return `Hello, my name is ${name}`; +} var greeting = createGreeting("Daniel"); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..68d20e81a 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,9 @@ // Declare your function first // Call the function and assign to a variable `sum` +function add(a, b) { + return a + b; +} +const sum = add(13, 124); console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..1b19342d3 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,7 @@ // 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); console.log(greeting); diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..47a512633 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,24 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; +const mentor1 = "Daniel"; +const mentor2 = "Irina"; +const mentor3 = "Mimi"; +const mentor4 = "Rob"; +const mentor5 = "Yohannes"; +const names = [mentor1, mentor2, mentor3, mentor4, mentor5]; +function upperCase(name) { + return name.toUpperCase(); +} + +function shouty(shout, name) { + const makeUppercase = upperCase(name); + return shout.concat(makeUppercase); +} +const printName1 = shouty("HELLO ", mentor1); +const printName2 = shouty("HELLO ", mentor2); +const printName3 = shouty("HELLO ", mentor3); +const printName4 = shouty("HELLO ", mentor4); +const printName5 = shouty("HELLO ", mentor5); +console.log(printName1); +console.log(printName2); +console.log(printName3); +console.log(printName4); +console.log(printName5); diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 75b3c6aab..7a400f197 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -3,10 +3,13 @@ =================== The business is breaking out into a new market and need to convert prices to USD Write a function that converts a price to USD (exchange rate is 1.4 $ to £) + test -- --testPathPattern 1-currency-conversion */ -function convertToUSD() {} - +function convertToUSD(pound) { + return pound * 1.4; +} +// console.log(convertToUSD(10)); /* CURRENCY CONVERSION =================== @@ -15,7 +18,11 @@ 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(pound) { + const fee = pound / 100; + const exchange = (pound - fee) * 5.7; + return +exchange.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/extra/2-piping.js b/extra/2-piping.js index b4f8c4c1b..e35f27235 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -16,26 +16,28 @@ the final result to the variable goodCode */ -function add() { - +function add(a, b) { + return a + b; } -function multiply() { - +function multiply(a, b) { + return a * b; } -function format() { - +function format(num) { + return "£" + num; } -const startingValue = 2; +// const startingValue = (2 + 10) * 2; +const startingValue = (2 + 10) * 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = +// let badCode = format(startingValue); +let badCode = format(startingValue); /* BETTER PRACTICE */ -let goodCode = +let goodCode = format(startingValue); /* ======= 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/3-magic-8-ball.js b/extra/3-magic-8-ball.js index 46f65f928..0a9f95dc5 100644 --- a/extra/3-magic-8-ball.js +++ b/extra/3-magic-8-ball.js @@ -45,8 +45,13 @@ // This should log "The ball has shaken!" // and return the answer. + function shakeBall() { //Write your code in here + // const answers = ["very positive", "positive", "negative", "very negative"]; + // return answers[Math.floor(Math.random() * answers.length)]; + console.log("The ball has shaken!"); + return Math.floor(Math.random() * 4); } /* @@ -58,8 +63,16 @@ function shakeBall() { This function should expect to be called with any value which was returned by the shakeBall function. */ + function checkAnswer(answer) { - //Write your code in here + // let ques = shakeBall(); + const answers = ["very positive", "positive", "negative", "very negative"]; + return answer + ? answers[Math.floor(Math.random() * answers.length)] + : "My reply is no."; + // const answers = ["very positive", "positive", "negative", "very negative"]; + // let a = answers[Math.floor(Math.random() * answers.length)]; + // return a.length === ques ? a : "My reply is no."; } /* @@ -101,7 +114,9 @@ test("magic 8 ball returns different values each time", () => { ); } - let seenPositivities = new Set(Array.from(seenAnswers.values()).map(checkAnswer)); + let seenPositivities = new Set( + Array.from(seenAnswers.values()).map(checkAnswer) + ); if (seenPositivities.size < 2) { throw Error( "Expected to random answers with different positivities each time shakeBall was called, but always got the same one" diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..730b464ac 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; + 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..0b400b47b 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,18 @@ // The syntax for this function is valid but it has an error, find it and fix it. +function wordtrim(str) { + return str.trim(); +} function trimWord(word) { - return wordtrim(); + return wordtrim(word); } 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..3479c06ab 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,16 +1,21 @@ // Add comments to explain what this function does. You're meant to use Google! + function getRandomNumber() { return Math.random() * 10; + //random returns with 10 will result in a max value of 9.999 } // Add comments to explain what this function does. You're meant to use Google! function combine2Words(word1, word2) { return word1.concat(word2); + // join word1 to word2 together as a string. + //Concatenation is the process of appending one string to the end of another 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} ${secondWord} ${thirdWord}`; } /* diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..0eb595efe 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(price) { + let taxOf = (price * 20) / 100; + return taxOf + price; +} /* CURRENCY FORMATTING @@ -17,7 +20,11 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(price) { + let taxOf = (price * 20) / 100; + let total = taxOf + price; + return `£${total.toFixed(2)}`; +} /* =================================================== From 362acc46c1c6cc6abe8607563864611f7d2fbf97 Mon Sep 17 00:00:00 2001 From: Rebwar Date: Fri, 26 Aug 2022 01:55:17 +0100 Subject: [PATCH 2/7] log the number of students and number of mentors as well as the total number. --- exercises/G-numbers/exercise.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index c58efb4ae..b57dd5099 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -3,4 +3,8 @@ const numberOfStudents = 15; const numberOfMentors = 8; const total = numberOfStudents + numberOfMentors; -console.log(`the total number of students and mentors are ${total}`); +console.log( + `Number of students: ${numberOfStudents} +Number of mentors: ${numberOfMentors} +Total number of students and mentors: ${total}` +); From ac0fa0edf232533926208f69573fe09574268d90 Mon Sep 17 00:00:00 2001 From: Rebwar Date: Fri, 26 Aug 2022 01:59:25 +0100 Subject: [PATCH 3/7] delete an Array which unused --- exercises/L-functions-nested/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index 47a512633..518a1be58 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,7 +3,7 @@ const mentor2 = "Irina"; const mentor3 = "Mimi"; const mentor4 = "Rob"; const mentor5 = "Yohannes"; -const names = [mentor1, mentor2, mentor3, mentor4, mentor5]; + function upperCase(name) { return name.toUpperCase(); } From 578d8563146a9cb6e6a6743825770e9d0eb20228 Mon Sep 17 00:00:00 2001 From: Rebwar Date: Fri, 26 Aug 2022 02:32:02 +0100 Subject: [PATCH 4/7] add BETTER PRACTICE solution and pass all of test --- extra/2-piping.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extra/2-piping.js b/extra/2-piping.js index e35f27235..c994620e7 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -37,7 +37,9 @@ let badCode = format(startingValue); /* BETTER PRACTICE */ -let goodCode = format(startingValue); +let goodCode = format(24); +let goodCode1 = add(10, 2); +let goodCode2 = multiply(10, 2); /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. From fc1c1656fec24dc1442c1714cbbbe2c6b70ad438 Mon Sep 17 00:00:00 2001 From: Rebwar Date: Fri, 26 Aug 2022 02:48:57 +0100 Subject: [PATCH 5/7] mandatory/3-function-output.js I mention that the lowest value is 0. --- mandatory/3-function-output.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 3479c06ab..9a488be89 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -2,7 +2,7 @@ function getRandomNumber() { return Math.random() * 10; - //random returns with 10 will result in a max value of 9.999 + //random returns with 10 will result in a max value of 9.999 and the lowest value is 0 } // Add comments to explain what this function does. You're meant to use Google! From a9e7b39cff91f813e358110f376e68e95264d673 Mon Sep 17 00:00:00 2001 From: Rebwar Date: Tue, 30 Aug 2022 03:04:31 +0100 Subject: [PATCH 6/7] edit extra/2-piping.js --- extra/2-piping.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extra/2-piping.js b/extra/2-piping.js index c994620e7..f066ae204 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -37,9 +37,9 @@ let badCode = format(startingValue); /* BETTER PRACTICE */ -let goodCode = format(24); -let goodCode1 = add(10, 2); -let goodCode2 = multiply(10, 2); +let sum = add(10, 2); +let increase = multiply(sum, 2); +let goodCode = format(increase); /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. From e0f9e8121cbc9838fc12d1cf8c7d89e2be195c2c Mon Sep 17 00:00:00 2001 From: Rebwar Date: Sun, 18 Sep 2022 21:48:13 +0100 Subject: [PATCH 7/7] 3-magic-8-ball --- .github/labels.json | 2 +- .github/pull_request_template.md | 72 ++--- .github/teams.yml | 6 +- .github/workflows/close.yml | 34 +- .github/workflows/extra-tests.yml | 28 +- .github/workflows/mandatory-tests.yml | 22 +- .github/workflows/team-labeler.yml | 26 +- .gitignore | 4 +- GRADING.md | 38 +-- HOW-TO-GET-HELP.md | 74 ++--- HOW-TO-SUBMIT.md | 46 +-- HOW_TO_MARK.md | 128 ++++---- README.md | 86 ++--- exercises/A-setup-ide/README.md | 26 +- exercises/B-hello-world/README.md | 36 +-- exercises/B-hello-world/exercise.js | 8 +- exercises/C-variables/README.md | 52 +-- exercises/C-variables/exercise.js | 18 +- exercises/D-strings/README.md | 58 ++-- exercises/D-strings/exercise.js | 16 +- exercises/E-strings-concatenation/README.md | 40 +-- exercises/E-strings-concatenation/exercise.js | 12 +- exercises/F-strings-methods/README.md | 80 ++--- exercises/F-strings-methods/exercise.js | 16 +- exercises/F-strings-methods/exercise2.js | 28 +- exercises/G-numbers/README.md | 58 ++-- exercises/G-numbers/exercise.js | 20 +- exercises/I-floats/README.md | 46 +-- exercises/I-floats/exercise.js | 42 +-- exercises/J-functions/README.md | 84 ++--- exercises/J-functions/exercise.js | 20 +- exercises/J-functions/exercise2.js | 22 +- exercises/K-functions-parameters/README.md | 140 ++++---- exercises/K-functions-parameters/exercise.js | 20 +- exercises/K-functions-parameters/exercise2.js | 16 +- exercises/K-functions-parameters/exercise3.js | 16 +- exercises/K-functions-parameters/exercise4.js | 18 +- exercises/K-functions-parameters/exercise5.js | 14 +- exercises/L-functions-nested/README.md | 68 ++-- exercises/L-functions-nested/exercise.js | 48 +-- extra/1-currency-conversion.js | 96 +++--- extra/2-piping.js | 154 ++++----- extra/3-magic-8-ball.js | 300 ++++++++++-------- mandatory/1-syntax-errors.js | 80 ++--- mandatory/2-logic-error.js | 106 +++---- mandatory/3-function-output.js | 84 ++--- mandatory/4-tax.js | 124 ++++---- package.json | 68 ++-- 48 files changed, 1317 insertions(+), 1283 deletions(-) diff --git a/.github/labels.json b/.github/labels.json index 330a995d1..a08f48068 100644 --- a/.github/labels.json +++ b/.github/labels.json @@ -1 +1 @@ -[{"name":"Improvement", "color":"0000ff", "description":"Improvement to this coursework" }] +[{"name":"Improvement", "color":"0000ff", "description":"Improvement to this coursework" }] diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 46c150e15..4216cc9f1 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,36 +1,36 @@ - - -**Volunteers: Are you marking this coursework?** _You can find a guide on how to mark this coursework in `HOW_TO_MARK.md` in the root of this repository_ - -# Your Details - -- Your Name: -- Your City: -- Your Slack Name: - -# Homework Details - -- Module: -- Week: - -# Notes - -- What did you find easy? - -- What did you find hard? - -- What do you still not understand? - -- Any other notes? + + +**Volunteers: Are you marking this coursework?** _You can find a guide on how to mark this coursework in `HOW_TO_MARK.md` in the root of this repository_ + +# Your Details + +- Your Name: +- Your City: +- Your Slack Name: + +# Homework Details + +- Module: +- Week: + +# Notes + +- What did you find easy? + +- What did you find hard? + +- What do you still not understand? + +- Any other notes? diff --git a/.github/teams.yml b/.github/teams.yml index 347c7d9c1..d9d095c9d 100644 --- a/.github/teams.yml +++ b/.github/teams.yml @@ -1,3 +1,3 @@ -Improvement: - - '@ChrisOwen101' - - 'ChrisOwen101' +Improvement: + - '@ChrisOwen101' + - 'ChrisOwen101' diff --git a/.github/workflows/close.yml b/.github/workflows/close.yml index 137dc57e9..59f4d14d1 100644 --- a/.github/workflows/close.yml +++ b/.github/workflows/close.yml @@ -1,17 +1,17 @@ -name: "Close stale issues and PRs" -on: - workflow_dispatch: - schedule: - - cron: "30 1 * * *" - -jobs: - stale: - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v3 - with: - stale-pr-message: "Your coursework submission has been closed because nobody has interacted with it in six weeks. You are welcome to re-open it to get more feedback." - days-before-stale: 42 - days-before-close: 0 - days-before-issue-stale: -1 - days-before-issue-close: -1 +name: "Close stale issues and PRs" +on: + workflow_dispatch: + schedule: + - cron: "30 1 * * *" + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v3 + with: + stale-pr-message: "Your coursework submission has been closed because nobody has interacted with it in six weeks. You are welcome to re-open it to get more feedback." + days-before-stale: 42 + days-before-close: 0 + days-before-issue-stale: -1 + days-before-issue-close: -1 diff --git a/.github/workflows/extra-tests.yml b/.github/workflows/extra-tests.yml index 2de5f0a34..e2ac0ec9a 100644 --- a/.github/workflows/extra-tests.yml +++ b/.github/workflows/extra-tests.yml @@ -1,14 +1,14 @@ -name: Run extra tests -on: - pull_request: - paths: - - extra/** -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install modules - run: npm install - - name: Run extra tests - run: npm test -- --selectProjects extra +name: Run extra tests +on: + pull_request: + paths: + - extra/** +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install modules + run: npm install + - name: Run extra tests + run: npm test -- --selectProjects extra diff --git a/.github/workflows/mandatory-tests.yml b/.github/workflows/mandatory-tests.yml index 253abb1b5..4b4d5735f 100644 --- a/.github/workflows/mandatory-tests.yml +++ b/.github/workflows/mandatory-tests.yml @@ -1,11 +1,11 @@ -name: Run mandatory tests -on: pull_request -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install modules - run: npm install - - name: Run mandatory tests - run: npm test -- --selectProjects mandatory +name: Run mandatory tests +on: pull_request +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install modules + run: npm install + - name: Run mandatory tests + run: npm test -- --selectProjects mandatory diff --git a/.github/workflows/team-labeler.yml b/.github/workflows/team-labeler.yml index eb2f8e32a..ac308305c 100644 --- a/.github/workflows/team-labeler.yml +++ b/.github/workflows/team-labeler.yml @@ -1,13 +1,13 @@ -name: "team-labeller" -on: - pull_request: - workflow_dispatch: - schedule: - - cron: "30 1 * * *" -jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: JulienKode/team-labeler-action@v0.1.0 - with: - repo-token: "${{ secrets.GITHUB_TOKEN }}" +name: "team-labeller" +on: + pull_request: + workflow_dispatch: + schedule: + - cron: "30 1 * * *" +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: JulienKode/team-labeler-action@v0.1.0 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.gitignore b/.gitignore index 936e5c57a..51edfb631 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/node_modules/ -/package-lock.json +/node_modules/ +/package-lock.json diff --git a/GRADING.md b/GRADING.md index b8ab587d2..2fc61fd56 100644 --- a/GRADING.md +++ b/GRADING.md @@ -1,19 +1,19 @@ - - -# Grading - -All coursework is graded using the Marking Guide found on the Syllabus. - -http://syllabus.codeyourfuture.io/guides/marking-guide - -If you have any questions on these guidelines - please ask. - -## Coding Standards - -Your code should follow our Coding Standards or it will be marked poorly. - -https://syllabus.codeyourfuture.io/guides/code-style-guide + + +# Grading + +All coursework is graded using the Marking Guide found on the Syllabus. + +http://syllabus.codeyourfuture.io/guides/marking-guide + +If you have any questions on these guidelines - please ask. + +## Coding Standards + +Your code should follow our Coding Standards or it will be marked poorly. + +https://syllabus.codeyourfuture.io/guides/code-style-guide diff --git a/HOW-TO-GET-HELP.md b/HOW-TO-GET-HELP.md index 56c70cafd..efa71bc33 100644 --- a/HOW-TO-GET-HELP.md +++ b/HOW-TO-GET-HELP.md @@ -1,37 +1,37 @@ - - -# How To Get Help - -When you get stuck it's important that you ask for help at the right time and in the right way - this means you will be able to solve you problem as quickly as possible! - -## Guide - -Please review our guide on the Syllabus for how to get help - -https://syllabus.codeyourfuture.io/guides/escalation-policy/ - -You should complete all of the steps in the order listed to get help - -## Reporting Issues in Coursework - -Is there a problem with this coursework? -Have you noticed a bug? -Does something not make sense? - -Post in the relevent channel on Slack depending on the module you are completing: - -- Git - `cyf-module-git` -- HTML/CSS - `cyf-module-html-css` -- JavaScript Core 1 - `cyf-module-js1` -- JavaScript Core 2 - `cyf-module-js2` -- JavaScript Core 2 - `cyf-module-js3` -- React - `cyf-module-react` -- Node - `cyf-module-node` -- SQL - `cyf-module-sql` -- MongoDB - `cyf-module-mongodb` - -None of these? Post in #cyf-syllabus. + + +# How To Get Help + +When you get stuck it's important that you ask for help at the right time and in the right way - this means you will be able to solve you problem as quickly as possible! + +## Guide + +Please review our guide on the Syllabus for how to get help + +https://syllabus.codeyourfuture.io/guides/escalation-policy/ + +You should complete all of the steps in the order listed to get help + +## Reporting Issues in Coursework + +Is there a problem with this coursework? +Have you noticed a bug? +Does something not make sense? + +Post in the relevent channel on Slack depending on the module you are completing: + +- Git - `cyf-module-git` +- HTML/CSS - `cyf-module-html-css` +- JavaScript Core 1 - `cyf-module-js1` +- JavaScript Core 2 - `cyf-module-js2` +- JavaScript Core 2 - `cyf-module-js3` +- React - `cyf-module-react` +- Node - `cyf-module-node` +- SQL - `cyf-module-sql` +- MongoDB - `cyf-module-mongodb` + +None of these? Post in #cyf-syllabus. diff --git a/HOW-TO-SUBMIT.md b/HOW-TO-SUBMIT.md index f9430423a..cb8843c72 100644 --- a/HOW-TO-SUBMIT.md +++ b/HOW-TO-SUBMIT.md @@ -1,23 +1,23 @@ - - -# How To Submit Your Coursework - -You should use Git & Github to submit your coursework as a pull request. - -You can use the Github Desktop cheatsheet here to help you do this. - -[Github Desktop Cheatsheet](http://syllabus.codeyourfuture.io/git/cheatsheet) - -You can also use this lesson to help you submit your coursework. - -[Git Lesson](http://syllabus.codeyourfuture.io/git/index) - -## Questions & Help - -Not being able to submit your coursework is not an excuse for not doing it. - -If you cannot submit your coursework you **must** message us on Slack to get help. + + +# How To Submit Your Coursework + +You should use Git & Github to submit your coursework as a pull request. + +You can use the Github Desktop cheatsheet here to help you do this. + +[Github Desktop Cheatsheet](http://syllabus.codeyourfuture.io/git/cheatsheet) + +You can also use this lesson to help you submit your coursework. + +[Git Lesson](http://syllabus.codeyourfuture.io/git/index) + +## Questions & Help + +Not being able to submit your coursework is not an excuse for not doing it. + +If you cannot submit your coursework you **must** message us on Slack to get help. diff --git a/HOW_TO_MARK.md b/HOW_TO_MARK.md index 99bf0f0f7..22b74691b 100644 --- a/HOW_TO_MARK.md +++ b/HOW_TO_MARK.md @@ -1,64 +1,64 @@ - - -_This file is useful for Volunteers only_ - -## 1) Solutions - -### 1.1) Where to find solutions? - -You can find the solution to this coursework in a repository with the same name as this but with `-Solution` after the name. - -For example, for this repo: - -https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1 - -The solutions would be found in: - -https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1-Solution - -**If you do not have access to these repositories** then please contact your City Coordinator to get access to our Github Team. - -### 1.2) Using the Solutions Repo - -In these repositories you will find solutions to each weeks coursework. These solutions are example answers and will not be the exact solution that students give. You should use it to inform your feedback of the coursework. - -Additionally, you will find marking guides in these places - -- The `marking` folder - Used to store multiple guides on marking -- `marking.md` file - Used to store notes on common problems we're trying to address -- `solutions.md` - A file used by students for notes on best practice - -## 2) Before You Start - -### 2.1) Feedback Guide - -A guide for marking coursework can be found here. Please read it before you start. - -https://docs.codeyourfuture.io/teams/education/homework-feedback - -### 2.2) Marking Guide - -Here is a useful resources you can direct students to when you see them have common mistakes - -https://syllabus.codeyourfuture.io/guides/marking-guide - -This guide should be used when you see a student making a common mistake so instead of writing out a reply you can send them to the a good resource. - -For example, if the student is leaving in lots of comments out code you could write - -```txt -Great work so far! - -It's best if you remove code that you're not using, you can read more about this here -https://syllabus.codeyourfuture.io/guides/marking-guide#commented-out-code -``` - -### 3.3) Style Guide - -All code at CYF should follow this Style Guide - -https://syllabus.codeyourfuture.io/guides/code-style-guide/ + + +_This file is useful for Volunteers only_ + +## 1) Solutions + +### 1.1) Where to find solutions? + +You can find the solution to this coursework in a repository with the same name as this but with `-Solution` after the name. + +For example, for this repo: + +https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1 + +The solutions would be found in: + +https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1-Solution + +**If you do not have access to these repositories** then please contact your City Coordinator to get access to our Github Team. + +### 1.2) Using the Solutions Repo + +In these repositories you will find solutions to each weeks coursework. These solutions are example answers and will not be the exact solution that students give. You should use it to inform your feedback of the coursework. + +Additionally, you will find marking guides in these places + +- The `marking` folder - Used to store multiple guides on marking +- `marking.md` file - Used to store notes on common problems we're trying to address +- `solutions.md` - A file used by students for notes on best practice + +## 2) Before You Start + +### 2.1) Feedback Guide + +A guide for marking coursework can be found here. Please read it before you start. + +https://docs.codeyourfuture.io/teams/education/homework-feedback + +### 2.2) Marking Guide + +Here is a useful resources you can direct students to when you see them have common mistakes + +https://syllabus.codeyourfuture.io/guides/marking-guide + +This guide should be used when you see a student making a common mistake so instead of writing out a reply you can send them to the a good resource. + +For example, if the student is leaving in lots of comments out code you could write + +```txt +Great work so far! + +It's best if you remove code that you're not using, you can read more about this here +https://syllabus.codeyourfuture.io/guides/marking-guide#commented-out-code +``` + +### 3.3) Style Guide + +All code at CYF should follow this Style Guide + +https://syllabus.codeyourfuture.io/guides/code-style-guide/ diff --git a/README.md b/README.md index dff05d7cd..f8a0189cc 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,43 @@ -# Coursework - -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 `extra` folder contains exercises that you can complete to challenge yourself, but are not required for the following lesson. - -## Running the code/tests - -The files for the mandatory/extra exercises are intended to be run as jest tests. - -- Once you have cloned the repository, run `npm install` once in the terminal to install jest (and any necessary dependencies). -- To run the tests for all mandatory/extra exercises, run `npm test` -- To run only the tests for the mandatory exercises, run `npm test -- --selectProjects mandatory` -- To run only the tests for the extra exercises, run `npm test -- --selectProjects extra` -- To run a single exercise/test (for example `mandatory/1-writer.js`), run `npm test -- --testPathPattern mandatory/1-writer.js` (Remember, you can use tab-completion to get files relative to the current directory, so m`Tab ↹`/1-`Tab ↹` will autocomplete get you the test file starting with 1-) - -For more information about tests, look here: - -https://syllabus.codeyourfuture.io/guides/intro-to-tests - -Try out variant way of running tests: - -- `npm test` -> run all mandatory and extra tests -- `npm test -- --selectProjects mandatory` -> run only mandatory tests -- `npm test -- --testPathPattern mandatory/1-syntax-errors.js` -> run single test - -## Solutions - -The solutions for this coursework can be found here: - -https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1-Solution - -This is a **private** repository. Please request access from your Teachers, Buddy or City Coordinator after the start of your next lesson. - -## Instructions for submission - -For your homework, we'll be using [**test driven development**](https://medium.com/@adityaalifnugraha/test-driven-development-tdd-in-a-nutshell-b9e05dfe8adb) to check your answers. Test driven development (or TDD) is the practice of writing tests for your code first, and then write your code to pass those tests. This is a very useful way of writing good quality code and is used in a lot of industries. You don't have to worry about knowing how this works, but if you're curious, engage with a volunteer to find out more! :) - -1. Complete the challenges in each file and save it once you're happy with your changes -2. Run the script to check the results against the tests - all tests should read PASSED if you completed the challenges correctly. If a test reads FAILED, find the associated test to identify which function failed and fix it. -3. Raise a PR once you're happy with the quality of your code +# Coursework + +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 `extra` folder contains exercises that you can complete to challenge yourself, but are not required for the following lesson. + +## Running the code/tests + +The files for the mandatory/extra exercises are intended to be run as jest tests. + +- Once you have cloned the repository, run `npm install` once in the terminal to install jest (and any necessary dependencies). +- To run the tests for all mandatory/extra exercises, run `npm test` +- To run only the tests for the mandatory exercises, run `npm test -- --selectProjects mandatory` +- To run only the tests for the extra exercises, run `npm test -- --selectProjects extra` +- To run a single exercise/test (for example `mandatory/1-writer.js`), run `npm test -- --testPathPattern mandatory/1-writer.js` (Remember, you can use tab-completion to get files relative to the current directory, so m`Tab ↹`/1-`Tab ↹` will autocomplete get you the test file starting with 1-) + +For more information about tests, look here: + +https://syllabus.codeyourfuture.io/guides/intro-to-tests + +Try out variant way of running tests: + +- `npm test` -> run all mandatory and extra tests +- `npm test -- --selectProjects mandatory` -> run only mandatory tests +- `npm test -- --testPathPattern mandatory/1-syntax-errors.js` -> run single test + +## Solutions + +The solutions for this coursework can be found here: + +https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1-Solution + +This is a **private** repository. Please request access from your Teachers, Buddy or City Coordinator after the start of your next lesson. + +## Instructions for submission + +For your homework, we'll be using [**test driven development**](https://medium.com/@adityaalifnugraha/test-driven-development-tdd-in-a-nutshell-b9e05dfe8adb) to check your answers. Test driven development (or TDD) is the practice of writing tests for your code first, and then write your code to pass those tests. This is a very useful way of writing good quality code and is used in a lot of industries. You don't have to worry about knowing how this works, but if you're curious, engage with a volunteer to find out more! :) + +1. Complete the challenges in each file and save it once you're happy with your changes +2. Run the script to check the results against the tests - all tests should read PASSED if you completed the challenges correctly. If a test reads FAILED, find the associated test to identify which function failed and fix it. +3. Raise a PR once you're happy with the quality of your code diff --git a/exercises/A-setup-ide/README.md b/exercises/A-setup-ide/README.md index de230419b..f1d3eaef1 100644 --- a/exercises/A-setup-ide/README.md +++ b/exercises/A-setup-ide/README.md @@ -1,13 +1,13 @@ -There are some tools that will help you to write code. One of these, [Prettier](https://prettier.io/), formats your code, making it easier for you and others to read. - -### 1. Install prettier - -- In Visual Studio open the extensions panel (see https://code.visualstudio.com/docs/editor/extension-gallery#_browse-and-install-extensions) -- Search for `Prettier - Code formatter` -- Click install on the top result - -### 2. Enable formatting on save - -- In Visual Studio open the settings file (see https://code.visualstudio.com/docs/getstarted/settings#_creating-user-and-workspace-settings) -- Search for `editor format` -- Set `editor.formatOnSave` and `editor.formatOnPaste` to true +There are some tools that will help you to write code. One of these, [Prettier](https://prettier.io/), formats your code, making it easier for you and others to read. + +### 1. Install prettier + +- In Visual Studio open the extensions panel (see https://code.visualstudio.com/docs/editor/extension-gallery#_browse-and-install-extensions) +- Search for `Prettier - Code formatter` +- Click install on the top result + +### 2. Enable formatting on save + +- In Visual Studio open the settings file (see https://code.visualstudio.com/docs/getstarted/settings#_creating-user-and-workspace-settings) +- Search for `editor format` +- Set `editor.formatOnSave` and `editor.formatOnPaste` to true diff --git a/exercises/B-hello-world/README.md b/exercises/B-hello-world/README.md index 27282c4af..4b743b96b 100644 --- a/exercises/B-hello-world/README.md +++ b/exercises/B-hello-world/README.md @@ -1,18 +1,18 @@ -It is programming tradition that the first thing you do in any language is make it output 'Hello world!'. - -We'll do this in JavaScript, using something called `console.log()`. - -Inside of `exercise.js` there's a line of code that will print "Hello world!". - -### 1. Run the program - -- Open a terminal window -- Change directory to this folder (`cd exercises/B-hello-world`) - assuming you're at the project root -- Run the program using node (`node exercise.js`) - -### 2. Experiment - -- Try to `console.log()` something different. For example, 'Hello World. I just started learning JavaScript!'. -- Try to console.log() several things at once. -- What happens when you get rid of the quote marks? -- What happens when you console.log() just a number without quotes? +It is programming tradition that the first thing you do in any language is make it output 'Hello world!'. + +We'll do this in JavaScript, using something called `console.log()`. + +Inside of `exercise.js` there's a line of code that will print "Hello world!". + +### 1. Run the program + +- Open a terminal window +- Change directory to this folder (`cd exercises/B-hello-world`) - assuming you're at the project root +- Run the program using node (`node exercise.js`) + +### 2. Experiment + +- Try to `console.log()` something different. For example, 'Hello World. I just started learning JavaScript!'. +- Try to console.log() several things at once. +- What happens when you get rid of the quote marks? +- What happens when you console.log() just a number without quotes? diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index fe18d1a4e..a048d1d60 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1,4 +1,4 @@ -console.log("Hello world"); -console.log("Hello World. I just started learning JavaScript!"); -console.log("Hello World!!! Just leave me alone!"); -console.log(4 ** 2); +console.log("Hello world"); +console.log("Hello World. I just started learning JavaScript!"); +console.log("Hello World!!! Just leave me alone!"); +console.log(4 ** 2); diff --git a/exercises/C-variables/README.md b/exercises/C-variables/README.md index 40859b3a8..9b0867773 100644 --- a/exercises/C-variables/README.md +++ b/exercises/C-variables/README.md @@ -1,26 +1,26 @@ -When you write code, you'll want to create shortcuts to data values so you can don't have to write out the same value every time. - -We can use _variable_ to create a reference to a value. - -```js -var greeting = "Hello world"; - -console.log(greeting); -``` - -The program above will print "Hello world" to the console. Notice how it uses the value assigned to the variable `greeting`. - -## Exercise - -- 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 `C-variables`. If you already have a terminal window open for the previous exercise you can do this by running the command `cd ../C-variables`. - -## Expected result - -``` -Hello world -Hello world -Hello world -``` +When you write code, you'll want to create shortcuts to data values so you can don't have to write out the same value every time. + +We can use _variable_ to create a reference to a value. + +```js +var greeting = "Hello world"; + +console.log(greeting); +``` + +The program above will print "Hello world" to the console. Notice how it uses the value assigned to the variable `greeting`. + +## Exercise + +- 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 `C-variables`. If you already have a terminal window open for the previous exercise you can do this by running the command `cd ../C-variables`. + +## Expected result + +``` +Hello world +Hello world +Hello world +``` diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index 6d7ae625d..8f1c0f626 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,9 +1,9 @@ -// Start by creating a variable `greeting` -let greeting = "Hello world!"; -console.log(greeting.repeat(3)); -greeting = ["Hello world!", "Hello world!", "Hello world!"]; -function repeat3Time(greeting) { - return greeting.map((str) => str); -} -const result = repeat3Time(greeting); -console.log(...result); +// Start by creating a variable `greeting` +let greeting = "Hello world!"; +console.log(greeting.repeat(3)); +greeting = ["Hello world!", "Hello world!", "Hello world!"]; +function repeat3Time(greeting) { + return greeting.map((str) => str); +} +const result = repeat3Time(greeting); +console.log(...result); diff --git a/exercises/D-strings/README.md b/exercises/D-strings/README.md index fd0a664ae..3f5887c0c 100644 --- a/exercises/D-strings/README.md +++ b/exercises/D-strings/README.md @@ -1,29 +1,29 @@ -In programming there are different _types of_ data. You've used one data type already: **string**. - -Computers recognise strings as a sequence of characters but to humans, strings are simply lines of text. - -```js -var message = "This is a string"; -``` - -Notice that strings are always wrapped **inside of quote marks**. We do this so that the computer knows when the string starts and ends. - -You can check that the data is a string by using the `typeof` operator: - -```js -var message = "This is a string"; -var messageType = typeof message; - -console.log(messageType); // logs 'string' -``` - -## Exercise - -- Write a program that logs a message and its type - -## Expected result - -``` -This is a string -string -``` +In programming there are different _types of_ data. You've used one data type already: **string**. + +Computers recognise strings as a sequence of characters but to humans, strings are simply lines of text. + +```js +var message = "This is a string"; +``` + +Notice that strings are always wrapped **inside of quote marks**. We do this so that the computer knows when the string starts and ends. + +You can check that the data is a string by using the `typeof` operator: + +```js +var message = "This is a string"; +var messageType = typeof message; + +console.log(messageType); // logs 'string' +``` + +## Exercise + +- Write a program that logs a message and its type + +## Expected result + +``` +This is a string +string +``` diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 6371e0dee..5d89feca4 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,8 +1,8 @@ -// Start by creating a variable `message` -function messageType(massage) { - return `This is a ${typeof massage} and type of ${typeof massage} is: ${typeof massage}`; -} -const message = messageType("Rebwar"); -console.log(message); -console.log(messageType(5)); -console.log(messageType({})); +// Start by creating a variable `message` +function messageType(massage) { + return `This is a ${typeof massage} and type of ${typeof massage} is: ${typeof massage}`; +} +const message = messageType("Rebwar"); +console.log(message); +console.log(messageType(5)); +console.log(messageType({})); diff --git a/exercises/E-strings-concatenation/README.md b/exercises/E-strings-concatenation/README.md index cba54dbca..9427124d9 100644 --- a/exercises/E-strings-concatenation/README.md +++ b/exercises/E-strings-concatenation/README.md @@ -1,20 +1,20 @@ -You can add two strings together using the plus operator (`+`): - -```js -var greetingStart = "Hello, my name is "; -var name = "Daniel"; - -var greeting = greetingStart + name; - -console.log(greeting); // Logs "Hello, my name is Daniel" -``` - -## Exercise - -- Write a program that logs a message with a greeting and your name - -## Expected result - -``` -Hello, my name is Daniel -``` +You can add two strings together using the plus operator (`+`): + +```js +var greetingStart = "Hello, my name is "; +var name = "Daniel"; + +var greeting = greetingStart + name; + +console.log(greeting); // Logs "Hello, my name is Daniel" +``` + +## Exercise + +- Write a program that logs a message with a greeting and your name + +## Expected result + +``` +Hello, my name is Daniel +``` diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 7f4b40ef6..11c4efe00 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,6 +1,6 @@ -// Start by creating a variable `message` -const greetingStart = "Hello, my name is "; -const name = "Rebwar"; - -const message = greetingStart + name; -console.log(message); +// Start by creating a variable `message` +const greetingStart = "Hello, my name is "; +const name = "Rebwar"; + +const message = greetingStart + name; +console.log(message); diff --git a/exercises/F-strings-methods/README.md b/exercises/F-strings-methods/README.md index fb07ec8ef..1798bdf16 100644 --- a/exercises/F-strings-methods/README.md +++ b/exercises/F-strings-methods/README.md @@ -1,40 +1,40 @@ -You can find out how many characters there are in a string by using the `length` property of a string: - -```js -var name = "Daniel"; -var nameLength = name.length; - -console.log(nameLength); // Logs 6 -``` - -You can also get a modified version of a string by calling _string methods_. Let's try one: - -```js -var name = "Daniel"; -var nameLowerCase = name.toLowerCase(); - -console.log(nameLowerCase); // "daniel" -``` - -You can find out more about string properties and methods by searching for "JavaScript string methods". - -## Exercise 1 - -- Log a message that includes the length of your name - -## Expected result - -``` -My name is Daniel and my name is 6 characters long -``` - -## Exercise 2 - -- Log the same message using the variable, `name` provided -- Use the `.trim` method to remove the extra whitespace - -## Expected result - -``` -My name is Daniel and my name is 6 characters long -``` +You can find out how many characters there are in a string by using the `length` property of a string: + +```js +var name = "Daniel"; +var nameLength = name.length; + +console.log(nameLength); // Logs 6 +``` + +You can also get a modified version of a string by calling _string methods_. Let's try one: + +```js +var name = "Daniel"; +var nameLowerCase = name.toLowerCase(); + +console.log(nameLowerCase); // "daniel" +``` + +You can find out more about string properties and methods by searching for "JavaScript string methods". + +## Exercise 1 + +- Log a message that includes the length of your name + +## Expected result + +``` +My name is Daniel and my name is 6 characters long +``` + +## Exercise 2 + +- Log the same message using the variable, `name` provided +- Use the `.trim` method to remove the extra whitespace + +## Expected result + +``` +My name is Daniel and my name is 6 characters long +``` diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index d8c09d280..ef657d235 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,8 +1,8 @@ -// Start by creating a variable `message` - -function lengthOfName(name) { - let trimeStr = name.replace(/\s/g, ""); - return `my name is ${name} and my name is ${trimeStr.length} characters long`; -} -const message = lengthOfName("Rebwar Azizi"); -console.log(message); +// Start by creating a variable `message` + +function lengthOfName(name) { + let trimeStr = name.replace(/\s/g, ""); + return `my name is ${name} and my name is ${trimeStr.length} characters long`; +} +const message = lengthOfName("Rebwar Azizi"); +console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index 4eabfa760..54a4ec3bc 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,14 +1,14 @@ -function lengthTrim(name) { - let trimeStr = name.trim(); - return `my name is ${name} and my name is ${trimeStr.length} characters long`; -} -function lengthRegEx(name) { - let trimeStr = name.replace(/\s/g, ""); - return `my name is ${name} and my name is ${trimeStr.length} characters long`; -} -const nametrim = " Rebwar a "; -const nameReqEx = " Rebwar a "; -const messagetrim = lengthTrim(nametrim); -const messageRegEx = lengthRegEx(nameReqEx); -console.log(`length with trim(): ${messagetrim}`); -console.log(`length with RegExp: ${messageRegEx}`); +function lengthTrim(name) { + let trimeStr = name.trim(); + return `my name is ${name} and my name is ${trimeStr.length} characters long`; +} +function lengthRegEx(name) { + let trimeStr = name.replace(/\s/g, ""); + return `my name is ${name} and my name is ${trimeStr.length} characters long`; +} +const nametrim = " Rebwar a "; +const nameReqEx = " Rebwar a "; +const messagetrim = lengthTrim(nametrim); +const messageRegEx = lengthRegEx(nameReqEx); +console.log(`length with trim(): ${messagetrim}`); +console.log(`length with RegExp: ${messageRegEx}`); diff --git a/exercises/G-numbers/README.md b/exercises/G-numbers/README.md index 6775ad18f..c02af2ca0 100644 --- a/exercises/G-numbers/README.md +++ b/exercises/G-numbers/README.md @@ -1,29 +1,29 @@ -The next data type we will learn is **number**. - -Unlike strings, numbers do not need to be wrapped in quotes. - -```js -var age = 30; -``` - -You can use mathematical operators to caclulate numbers: - -```js -var sum = 10 + 2; // 12 -var product = 10 * 2; // 20 -var quotient = 10 / 2; // 5 -var difference = 10 - 2; // 8 -``` - -## Exercise - -- Create two variables `numberOfStudents` and `numberOfMentors` -- Log a message that displays the total number of students and mentors - -## Expected result - -``` -Number of students: 15 -Number of mentors: 8 -Total number of students and mentors: 23 -``` +The next data type we will learn is **number**. + +Unlike strings, numbers do not need to be wrapped in quotes. + +```js +var age = 30; +``` + +You can use mathematical operators to caclulate numbers: + +```js +var sum = 10 + 2; // 12 +var product = 10 * 2; // 20 +var quotient = 10 / 2; // 5 +var difference = 10 - 2; // 8 +``` + +## Exercise + +- Create two variables `numberOfStudents` and `numberOfMentors` +- Log a message that displays the total number of students and mentors + +## Expected result + +``` +Number of students: 15 +Number of mentors: 8 +Total number of students and mentors: 23 +``` diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index b57dd5099..e79710855 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1,10 +1,10 @@ -// Start by creating a variables `numberOfStudents` and `numberOfMentors` - -const numberOfStudents = 15; -const numberOfMentors = 8; -const total = numberOfStudents + numberOfMentors; -console.log( - `Number of students: ${numberOfStudents} -Number of mentors: ${numberOfMentors} -Total number of students and mentors: ${total}` -); +// Start by creating a variables `numberOfStudents` and `numberOfMentors` + +const numberOfStudents = 15; +const numberOfMentors = 8; +const total = numberOfStudents + numberOfMentors; +console.log( + `Number of students: ${numberOfStudents} +Number of mentors: ${numberOfMentors} +Total number of students and mentors: ${total}` +); diff --git a/exercises/I-floats/README.md b/exercises/I-floats/README.md index bbc9e29c2..c257f8bc8 100644 --- a/exercises/I-floats/README.md +++ b/exercises/I-floats/README.md @@ -1,23 +1,23 @@ -Numbers can be integers (whole numbers) or floats (numbers with a decimal). - -```js -var preciseAge = 30.612437; -``` - -Floats can be rounded to the nearest whole number using the `Math.round` function: - -```js -var preciseAge = 30.612437; -var roughAge = Math.round(preciseAge); // 30 -``` - -## Exercise - -- Using the variables provided in the exercise calculate the percentage of mentors and students in the group - -## Expected result - -``` -Percentage students: 65% -Percentage mentors: 35% -``` +Numbers can be integers (whole numbers) or floats (numbers with a decimal). + +```js +var preciseAge = 30.612437; +``` + +Floats can be rounded to the nearest whole number using the `Math.round` function: + +```js +var preciseAge = 30.612437; +var roughAge = Math.round(preciseAge); // 30 +``` + +## Exercise + +- Using the variables provided in the exercise calculate the percentage of mentors and students in the group + +## Expected result + +``` +Percentage students: 65% +Percentage mentors: 35% +``` diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index 61a1ad0fb..258a3f3ff 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,21 +1,21 @@ -const numberOfStudents = 15; -const numberOfMentors = 8; - -function percentageNumber(num1, num2, percentage) { - const sum = num1 + num2; - return Math.round((100 / sum) * percentage); -} - -const students = percentageNumber( - numberOfStudents, - numberOfMentors, - numberOfStudents -); - -const mentors = percentageNumber( - numberOfStudents, - numberOfMentors, - numberOfMentors -); -console.log(`Percentage students: ${students}%`); -console.log(`Percentage mentors: ${mentors}%`); +const numberOfStudents = 15; +const numberOfMentors = 8; + +function percentageNumber(num1, num2, percentage) { + const sum = num1 + num2; + return Math.round((100 / sum) * percentage); +} + +const students = percentageNumber( + numberOfStudents, + numberOfMentors, + numberOfStudents +); + +const mentors = percentageNumber( + numberOfStudents, + numberOfMentors, + numberOfMentors +); +console.log(`Percentage students: ${students}%`); +console.log(`Percentage mentors: ${mentors}%`); diff --git a/exercises/J-functions/README.md b/exercises/J-functions/README.md index 22105ca2a..1be896f69 100644 --- a/exercises/J-functions/README.md +++ b/exercises/J-functions/README.md @@ -1,42 +1,42 @@ -Functions are blocks of code that can do a task as many times as you ask it to. They take an input and return an output. - -Here's a function that doubles a number: - -```js -function double(number) { - return number * 2; -} -``` - -To use the function we need to: -a) _call_ it with an input and -b) assign the returned value to a variable - -```js -var result = double(2); - -console.log(result); // 4 -``` - -## Exercise - -- Complete the function in exercise.js so that it halves the input -- Try calling the function more than once with some different numbers - -> Remember to use the return keyword to get a value out of the function - -## Expected result - -``` -6 -``` - -## Exercise 2 - -- Complete the function in exercise2.js so that it triples the input - -## Expected result - -``` -36 -``` +Functions are blocks of code that can do a task as many times as you ask it to. They take an input and return an output. + +Here's a function that doubles a number: + +```js +function double(number) { + return number * 2; +} +``` + +To use the function we need to: +a) _call_ it with an input and +b) assign the returned value to a variable + +```js +var result = double(2); + +console.log(result); // 4 +``` + +## Exercise + +- Complete the function in exercise.js so that it halves the input +- Try calling the function more than once with some different numbers + +> Remember to use the return keyword to get a value out of the function + +## Expected result + +``` +6 +``` + +## Exercise 2 + +- Complete the function in exercise2.js so that it triples the input + +## Expected result + +``` +36 +``` diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index d25d80d5a..74b61e2ab 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,10 +1,10 @@ -function halve(number) { - return number / 2; -} - -const result = halve(12); -const result1 = halve(100); -const result2 = halve(88); -console.log(result); -console.log(result1); -console.log(result2); +function halve(number) { + return number / 2; +} + +const result = halve(12); +const result1 = halve(100); +const result2 = halve(88); +console.log(result); +console.log(result1); +console.log(result2); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 1e2a72f32..11564ddf3 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,11 +1,11 @@ -function triple(number) { - return number * 3; -} - -const result = triple(12); -const result1 = triple(35); -const result2 = triple(50); - -console.log(result); -console.log(result1); -console.log(result2); +function triple(number) { + return number * 3; +} + +const result = triple(12); +const result1 = triple(35); +const result2 = triple(50); + +console.log(result); +console.log(result1); +console.log(result2); diff --git a/exercises/K-functions-parameters/README.md b/exercises/K-functions-parameters/README.md index 1614e221b..b7ff14b7c 100644 --- a/exercises/K-functions-parameters/README.md +++ b/exercises/K-functions-parameters/README.md @@ -1,70 +1,70 @@ -The input given to a function is called a **parameter**. - -A function can take more than one parameter: - -```js -function add(a, b) { - return a + b; -} -``` - -When you write a function (sometimes called _declaring a function_) you assign names to the parameters inside of the parentheses (`()`). Parameters can be called anything. - -This function is exactly the same as the on above: - -```js -function add(num1, num2) { - return num1 + num2; -} -``` - -## Exercise - -- Write a function that multiplies two numbers together - -## Expected result - -``` -12 -``` - -## Exercise 2 - -- From scratch, write a function that divides two numbers - -## Expected result - -``` -0.75 -``` - -## Exercise 3 - -- Write a function that takes a name (a string) and returns a greeting - -## Expected result - -``` -Hello, my name is Daniel -``` - -## Exercise 4 - -- Write a function that adds two numbers together -- Call the function, passing `13` and `124` as parameters, and assigning the returned value to a variable `sum` - -## Expected result - -``` -137 -``` - -## Exercise 5 - -- Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string) - -## Expected result - -``` -Hello, my name is Daniel and I'm 30 years old -``` +The input given to a function is called a **parameter**. + +A function can take more than one parameter: + +```js +function add(a, b) { + return a + b; +} +``` + +When you write a function (sometimes called _declaring a function_) you assign names to the parameters inside of the parentheses (`()`). Parameters can be called anything. + +This function is exactly the same as the on above: + +```js +function add(num1, num2) { + return num1 + num2; +} +``` + +## Exercise + +- Write a function that multiplies two numbers together + +## Expected result + +``` +12 +``` + +## Exercise 2 + +- From scratch, write a function that divides two numbers + +## Expected result + +``` +0.75 +``` + +## Exercise 3 + +- Write a function that takes a name (a string) and returns a greeting + +## Expected result + +``` +Hello, my name is Daniel +``` + +## Exercise 4 + +- Write a function that adds two numbers together +- Call the function, passing `13` and `124` as parameters, and assigning the returned value to a variable `sum` + +## Expected result + +``` +137 +``` + +## Exercise 5 + +- Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string) + +## Expected result + +``` +Hello, my name is Daniel and I'm 30 years old +``` diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index dbd50454d..7ef0f542e 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,10 +1,10 @@ -// Complete the function so that it takes input parameters -function multiply(a, b) { - // Calculate the result of the function and return it - return a * b; -} - -// Assign the result of calling the function the variable `result` -var result = multiply(3, 4); - -console.log(result); +// Complete the function so that it takes input parameters +function multiply(a, b) { + // Calculate the result of the function and return it + return a * b; +} + +// Assign the result of calling the function the variable `result` +var result = multiply(3, 4); + +console.log(result); diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index 3554839c1..d7f94cee6 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,8 +1,8 @@ -// Declare your function first -function divide(a, b) { - return a / b; -} - -const result = divide(3, 4); - -console.log(result); +// Declare your function first +function divide(a, b) { + return a / b; +} + +const result = divide(3, 4); + +console.log(result); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index e928bd2de..5f170dba2 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,8 +1,8 @@ -// Write your function here -function createGreeting(name) { - return `Hello, my name is ${name}`; -} - -var greeting = createGreeting("Daniel"); - -console.log(greeting); +// Write your function here +function createGreeting(name) { + return `Hello, my name is ${name}`; +} + +var greeting = createGreeting("Daniel"); + +console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 68d20e81a..6c328e9ef 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,9 +1,9 @@ -// Declare your function first - -// Call the function and assign to a variable `sum` -function add(a, b) { - return a + b; -} - -const sum = add(13, 124); -console.log(sum); +// Declare your function first + +// Call the function and assign to a variable `sum` +function add(a, b) { + return a + b; +} + +const sum = add(13, 124); +console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 1b19342d3..8fbbe6433 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,7 +1,7 @@ -// 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); - -console.log(greeting); +// 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); + +console.log(greeting); diff --git a/exercises/L-functions-nested/README.md b/exercises/L-functions-nested/README.md index 1c4ae9c8a..cd606cb99 100644 --- a/exercises/L-functions-nested/README.md +++ b/exercises/L-functions-nested/README.md @@ -1,34 +1,34 @@ -Functions are very powerful. - -- You can write more than one line of code inside of functions. -- You can use variables inside of functions. -- You can call other functions inside of functions! - -```js -function getAgeInDays(age) { - return age * 365; -} - -function createCreeting(name, age) { - var ageInDays = getAgeInDays(age); - var message = - "My Name is " + name + " and I was born over " + ageInDays + " days ago!"; - return message; -} -``` - -## Exercise 1 - -- In `exercise.js` you have been provided with the names of some mentors. Write a program that logs a shouty greeting to each one. -- Your program should include a function that spells their name in uppercase, and a function that creates a shouty greeting. -- Log each greeting to the console. - -## Expected result - -``` -HELLO DANIEL -HELLO IRINA -HELLO MIMI -HELLO ROB -HELLO YOHANNES -``` +Functions are very powerful. + +- You can write more than one line of code inside of functions. +- You can use variables inside of functions. +- You can call other functions inside of functions! + +```js +function getAgeInDays(age) { + return age * 365; +} + +function createCreeting(name, age) { + var ageInDays = getAgeInDays(age); + var message = + "My Name is " + name + " and I was born over " + ageInDays + " days ago!"; + return message; +} +``` + +## Exercise 1 + +- In `exercise.js` you have been provided with the names of some mentors. Write a program that logs a shouty greeting to each one. +- Your program should include a function that spells their name in uppercase, and a function that creates a shouty greeting. +- Log each greeting to the console. + +## Expected result + +``` +HELLO DANIEL +HELLO IRINA +HELLO MIMI +HELLO ROB +HELLO YOHANNES +``` diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index 518a1be58..0d84a9b69 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,24 +1,24 @@ -const mentor1 = "Daniel"; -const mentor2 = "Irina"; -const mentor3 = "Mimi"; -const mentor4 = "Rob"; -const mentor5 = "Yohannes"; - -function upperCase(name) { - return name.toUpperCase(); -} - -function shouty(shout, name) { - const makeUppercase = upperCase(name); - return shout.concat(makeUppercase); -} -const printName1 = shouty("HELLO ", mentor1); -const printName2 = shouty("HELLO ", mentor2); -const printName3 = shouty("HELLO ", mentor3); -const printName4 = shouty("HELLO ", mentor4); -const printName5 = shouty("HELLO ", mentor5); -console.log(printName1); -console.log(printName2); -console.log(printName3); -console.log(printName4); -console.log(printName5); +const mentor1 = "Daniel"; +const mentor2 = "Irina"; +const mentor3 = "Mimi"; +const mentor4 = "Rob"; +const mentor5 = "Yohannes"; + +function upperCase(name) { + return name.toUpperCase(); +} + +function shouty(shout, name) { + const makeUppercase = upperCase(name); + return shout.concat(makeUppercase); +} +const printName1 = shouty("HELLO ", mentor1); +const printName2 = shouty("HELLO ", mentor2); +const printName3 = shouty("HELLO ", mentor3); +const printName4 = shouty("HELLO ", mentor4); +const printName5 = shouty("HELLO ", mentor5); +console.log(printName1); +console.log(printName2); +console.log(printName3); +console.log(printName4); +console.log(printName5); diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 7a400f197..96e8d14a0 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -1,48 +1,48 @@ -/* - CURRENCY CONVERSION - =================== - The business is breaking out into a new market and need to convert prices to USD - Write a function that converts a price to USD (exchange rate is 1.4 $ to £) - test -- --testPathPattern 1-currency-conversion -*/ - -function convertToUSD(pound) { - return pound * 1.4; -} -// console.log(convertToUSD(10)); -/* - CURRENCY CONVERSION - =================== - The business is now breaking into the Brazilian market - Write a new function for converting to the Brazilian real (exchange rate is 5.7 BRL to £) - 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(pound) { - const fee = pound / 100; - const exchange = (pound - fee) * 5.7; - return +exchange.toFixed(2); -} - -/* ======= TESTS - DO NOT MODIFY ===== -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 1-currency-conversion` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -*/ - -test("convertToUSD function works for £32", () => { - expect(convertToUSD(32)).toEqual(44.8); -}); - -test("convertToUSD function works for £50", () => { - expect(convertToUSD(50)).toEqual(70); -}); - -test("convertToBRL function works for £30", () => { - expect(convertToBRL(30)).toEqual(169.29); -}); - -test("convertToBRL function works for £1.50", () => { - expect(convertToBRL(1.5)).toEqual(8.46); -}); +/* + CURRENCY CONVERSION + =================== + The business is breaking out into a new market and need to convert prices to USD + Write a function that converts a price to USD (exchange rate is 1.4 $ to £) + test -- --testPathPattern 1-currency-conversion +*/ + +function convertToUSD(pound) { + return pound * 1.4; +} +// console.log(convertToUSD(10)); +/* + CURRENCY CONVERSION + =================== + The business is now breaking into the Brazilian market + Write a new function for converting to the Brazilian real (exchange rate is 5.7 BRL to £) + 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(pound) { + const fee = pound / 100; + const exchange = (pound - fee) * 5.7; + return +exchange.toFixed(2); +} + +/* ======= TESTS - DO NOT MODIFY ===== +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 1-currency-conversion` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +*/ + +test("convertToUSD function works for £32", () => { + expect(convertToUSD(32)).toEqual(44.8); +}); + +test("convertToUSD function works for £50", () => { + expect(convertToUSD(50)).toEqual(70); +}); + +test("convertToBRL function works for £30", () => { + expect(convertToBRL(30)).toEqual(169.29); +}); + +test("convertToBRL function works for £1.50", () => { + expect(convertToBRL(1.5)).toEqual(8.46); +}); diff --git a/extra/2-piping.js b/extra/2-piping.js index f066ae204..716d6665b 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -1,77 +1,77 @@ -/* - PIPING FUNCTIONS - ================ - 1. Write 3 functions: - - one that adds 2 numbers together - - one that multiplies 2 numbers together - - one that formats a number so it's returned as a string with a £ sign before it (e.g. 20 -> £20) - - 2. Using the variable startingValue as input, perform the following operations using your functions all - on one line (assign the result to the variable badCode): - - add 10 to startingValue - - multiply the result by 2 - - format it - - 3. Write a more readable version of what you wrote in step 2 under the BETTER PRACTICE comment. Assign - the final result to the variable goodCode -*/ - -function add(a, b) { - return a + b; -} - -function multiply(a, b) { - return a * b; -} - -function format(num) { - return "£" + num; -} - -// const startingValue = (2 + 10) * 2; -const startingValue = (2 + 10) * 2; - -// Why can this code be seen as bad practice? Comment your answer. -// let badCode = format(startingValue); -let badCode = format(startingValue); - -/* BETTER PRACTICE */ - -let sum = add(10, 2); -let increase = multiply(sum, 2); -let goodCode = format(increase); - -/* ======= TESTS - DO NOT MODIFY ===== -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 2-piping` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -*/ - -test("add function - case 1 works", () => { - expect(add(1, 3)).toEqual(4); -}); - -test("add function - case 2 works", () => { - expect(add(2.4, 5)).toEqual(7.4); -}); - -test("multiply function works", () => { - expect(multiply(2, 3)).toEqual(6); -}); - -test("format function works for whole number", () => { - expect(format(16)).toEqual("£16"); -}); - -test("format function works for decimal number", () => { - expect(format(10.1)).toEqual("£10.1"); -}); - -test("badCode variable correctly assigned", () => { - expect(badCode).toEqual("£24"); -}); - -test("goodCode variable correctly assigned", () => { - expect(goodCode).toEqual("£24"); -}); +/* + PIPING FUNCTIONS + ================ + 1. Write 3 functions: + - one that adds 2 numbers together + - one that multiplies 2 numbers together + - one that formats a number so it's returned as a string with a £ sign before it (e.g. 20 -> £20) + + 2. Using the variable startingValue as input, perform the following operations using your functions all + on one line (assign the result to the variable badCode): + - add 10 to startingValue + - multiply the result by 2 + - format it + + 3. Write a more readable version of what you wrote in step 2 under the BETTER PRACTICE comment. Assign + the final result to the variable goodCode +*/ + +function add(a, b) { + return a + b; +} + +function multiply(a, b) { + return a * b; +} + +function format(num) { + return "£" + num; +} + +// const startingValue = (2 + 10) * 2; +const startingValue = (2 + 10) * 2; + +// Why can this code be seen as bad practice? Comment your answer. +// let badCode = format(startingValue); +let badCode = format(startingValue); + +/* BETTER PRACTICE */ + +let sum = add(10, 2); +let increase = multiply(sum, 2); +let goodCode = format(increase); + +/* ======= TESTS - DO NOT MODIFY ===== +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 2-piping` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +*/ + +test("add function - case 1 works", () => { + expect(add(1, 3)).toEqual(4); +}); + +test("add function - case 2 works", () => { + expect(add(2.4, 5)).toEqual(7.4); +}); + +test("multiply function works", () => { + expect(multiply(2, 3)).toEqual(6); +}); + +test("format function works for whole number", () => { + expect(format(16)).toEqual("£16"); +}); + +test("format function works for decimal number", () => { + expect(format(10.1)).toEqual("£10.1"); +}); + +test("badCode variable correctly assigned", () => { + expect(badCode).toEqual("£24"); +}); + +test("goodCode variable correctly assigned", () => { + expect(goodCode).toEqual("£24"); +}); diff --git a/extra/3-magic-8-ball.js b/extra/3-magic-8-ball.js index 0a9f95dc5..583af552a 100644 --- a/extra/3-magic-8-ball.js +++ b/extra/3-magic-8-ball.js @@ -1,133 +1,167 @@ -/** - - Let's peer into the future using a Magic 8 Ball! - https://en.wikipedia.org/wiki/Magic_8-Ball - - There are a few steps to being able view the future though: - * Ask a question - * Shake the ball - * Get an answer - * Decide if it's positive or negative - - The question can be anything, but the answers are fixed, - and have different levels of positivity or negativity. - - Below are the possible answers: - - ## Very positive - It is certain. - It is decidedly so. - Without a doubt. - Yes - definitely. - You may rely on it. - - ## Positive - As I see it, yes. - Most likely. - Outlook good. - Yes. - Signs point to yes. - - ## Negative - Reply hazy, try again. - Ask again later. - Better not tell you now. - Cannot predict now. - Concentrate and ask again. - - ## Very negative - Don't count on it. - My reply is no. - My sources say no. - Outlook not so good. - Very doubtful. -*/ - -// This should log "The ball has shaken!" -// and return the answer. - -function shakeBall() { - //Write your code in here - // const answers = ["very positive", "positive", "negative", "very negative"]; - // return answers[Math.floor(Math.random() * answers.length)]; - console.log("The ball has shaken!"); - return Math.floor(Math.random() * 4); -} - -/* - This function should say whether the answer it is given is - - very positive - - positive - - negative - - very negative - - This function should expect to be called with any value which was returned by the shakeBall function. -*/ - -function checkAnswer(answer) { - // let ques = shakeBall(); - const answers = ["very positive", "positive", "negative", "very negative"]; - return answer - ? answers[Math.floor(Math.random() * answers.length)] - : "My reply is no."; - // const answers = ["very positive", "positive", "negative", "very negative"]; - // let a = answers[Math.floor(Math.random() * answers.length)]; - // return a.length === ques ? a : "My reply is no."; -} - -/* -================================== -======= TESTS - DO NOT MODIFY ===== - -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 3-magic-8-ball` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -================================== -*/ - -test("whole magic 8 ball sequence", () => { - const consoleLogSpy = jest.spyOn(global.console, "log"); - const answer = shakeBall(); - - expect(typeof answer).toEqual("string"); - - expect(consoleLogSpy).toHaveBeenCalledTimes(1); - expect(consoleLogSpy).toHaveBeenLastCalledWith("The ball has shaken!"); - - expect(checkAnswer(answer)).toBeOneOf([ - "very positive", - "positive", - "negative", - "very negative", - ]); -}); - -test("magic 8 ball returns different values each time", () => { - const seenAnswers = new Set(); - for (let i = 0; i < 10; ++i) { - seenAnswers.add(shakeBall()); - } - if (seenAnswers.size < 2) { - throw Error( - "Expected to get different random answers each time shakeBall was called, but always got the same one" - ); - } - - let seenPositivities = new Set( - Array.from(seenAnswers.values()).map(checkAnswer) - ); - if (seenPositivities.size < 2) { - throw Error( - "Expected to random answers with different positivities each time shakeBall was called, but always got the same one" - ); - } -}); - -test("checkAnswer works for `It is decidedly so.`", () => { - expect(checkAnswer("It is decidedly so.")).toEqual("very positive"); -}); - -test("checkAnswer works for `My reply is no.`", () => { - expect(checkAnswer("My reply is no.")).toEqual("very negative"); -}); +/** + + Let's peer into the future using a Magic 8 Ball! + https://en.wikipedia.org/wiki/Magic_8-Ball + + There are a few steps to being able view the future though: + * Ask a question + * Shake the ball + * Get an answer + * Decide if it's positive or negative + + The question can be anything, but the answers are fixed, + and have different levels of positivity or negativity. + + Below are the possible answers: + + ## Very positive + It is certain. + It is decidedly so. + Without a doubt. + Yes - definitely. + You may rely on it. + + ## Positive + As I see it, yes. + Most likely. + Outlook good. + Yes. + Signs point to yes. + + ## Negative + Reply hazy, try again. + Ask again later. + Better not tell you now. + Cannot predict now. + Concentrate and ask again. + + ## Very negative + Don't count on it. + My reply is no. + My sources say no. + Outlook not so good. + Very doubtful. +*/ + +// This should log "The ball has shaken!" +// and return the answer. + +const veryNegativeAnswers = [ + "Don't count on it.", + "My reply is no.", + "My sources say no.", + "Outlook not so good.", + "Very doubtful.", +]; +const negativeAnswers = [ + "Reply hazy, try again.", + "Ask again later.", + "Better not tell you now.", + "Cannot predict now.", + "Concentrate and ask again.", +]; +const positiveAnswers = [ + "As I see it, yes.", + "Most likely.", + "Outlook good.", + "Yes.", + "Signs point to yes.", +]; +const veryPositiveAnswers = [ + "You may rely on it", + "You may rely on it", + "It is decidedly so.", + "It is certain.", +]; +const possibleAnswers = veryNegativeAnswers.concat( + negativeAnswers, + positiveAnswers, + veryPositiveAnswers +); +// console.log(possibleAnswers); +// This should log "The ball has shaken!" +// and return the answer. + +function shakeBall() { + const randomIndex = Math.floor(Math.random() * possibleAnswers.length); + const randomAnswer = possibleAnswers[randomIndex]; + const message = "The ball has shaken!"; + console.log(message); + return randomAnswer; +} +// console.log(shakeBall()); +// let r = shakeBall(); +/* + This function should say whether the answer it is given is + - very positive + - positive + - negative + - very negative + This function should expect to be called with any value which was returned by the shakeBall function. +*/ +function checkAnswer(answer) { + const answerIndex = possibleAnswers.indexOf(answer); + // console.log(answer); + // return answerIndex; + if (answerIndex >= 15) return "very positive"; + if (answerIndex >= 10) return "positive"; + if (answerIndex >= 5) return "negative"; + return "very negative"; +} +// console.log(checkAnswer(r)); +/* +================================== +======= TESTS - DO NOT MODIFY ===== + +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 3-magic-8-ball` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +================================== +*/ + +test("whole magic 8 ball sequence", () => { + const consoleLogSpy = jest.spyOn(global.console, "log"); + const answer = shakeBall(); + + expect(typeof answer).toEqual("string"); + + expect(consoleLogSpy).toHaveBeenCalledTimes(1); + expect(consoleLogSpy).toHaveBeenLastCalledWith("The ball has shaken!"); + + expect(checkAnswer(answer)).toBeOneOf([ + "very positive", + "positive", + "negative", + "very negative", + ]); +}); + +test("magic 8 ball returns different values each time", () => { + const seenAnswers = new Set(); + for (let i = 0; i < 10; ++i) { + seenAnswers.add(shakeBall()); + } + if (seenAnswers.size < 2) { + throw Error( + "Expected to get different random answers each time shakeBall was called, but always got the same one" + ); + } + + let seenPositivities = new Set( + Array.from(seenAnswers.values()).map(checkAnswer) + ); + if (seenPositivities.size < 2) { + throw Error( + "Expected to random answers with different positivities each time shakeBall was called, but always got the same one" + ); + } +}); + +test("checkAnswer works for `It is decidedly so.`", () => { + expect(checkAnswer("It is decidedly so.")).toEqual("very positive"); +}); + +test("checkAnswer works for `My reply is no.`", () => { + expect(checkAnswer("My reply is no.")).toEqual("very negative"); +}); \ No newline at end of file diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index 730b464ac..75326701a 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,40 +1,40 @@ -// There are syntax errors in this code - can you fix it to pass the tests? - -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 getTotal(a, b) { - total = a + b; - - return "The total is " + total; -} - -/* -=================================================== -======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== - -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 1-syntax-errors` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) - -=================================================== -*/ - -test("addNumbers adds numbers correctly", () => { - expect(addNumbers(3, 4, 6)).toEqual(13); -}); - -test("introduceMe function returns the correct string", () => { - expect(introduceMe("Sonjide", 27)).toEqual( - "Hello, my name is Sonjide and I am 27 years old" - ); -}); - -test("getTotal returns a string describing the total", () => { - expect(getTotal(23, 5)).toEqual("The total is 28"); -}); +// There are syntax errors in this code - can you fix it to pass the tests? + +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 getTotal(a, b) { + total = a + b; + + return "The total is " + total; +} + +/* +=================================================== +======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== + +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 1-syntax-errors` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) + +=================================================== +*/ + +test("addNumbers adds numbers correctly", () => { + expect(addNumbers(3, 4, 6)).toEqual(13); +}); + +test("introduceMe function returns the correct string", () => { + expect(introduceMe("Sonjide", 27)).toEqual( + "Hello, my name is Sonjide and I am 27 years old" + ); +}); + +test("getTotal returns a string describing the total", () => { + expect(getTotal(23, 5)).toEqual("The total is 28"); +}); diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 0b400b47b..1c609b6f0 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,53 +1,53 @@ -// The syntax for this function is valid but it has an error, find it and fix it. - -function wordtrim(str) { - return str.trim(); -} -function trimWord(word) { - return wordtrim(word); -} - -function getStringLength(word) { - return word.length; -} - -function multiply(a, b, c) { - return a * b * c; -} - -/* -=================================================== -======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== - -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 2-logic-error` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -=================================================== -*/ - -test("trimWord trims leading and trailing whitespace", () => { - expect(trimWord(" CodeYourFuture ")).toEqual("CodeYourFuture"); -}); - -test("trimWord doesn't remove whitespace in the middle of the string", () => { - expect(trimWord(" CodeYourFuture teaches coding ")).toEqual( - "CodeYourFuture teaches coding" - ); -}); - -test("getStringLength returns the length of a word", () => { - expect(getStringLength("Turtles")).toEqual(7); -}); - -test("getStringLength returns the length of a sentence", () => { - expect(getStringLength("A wild sentence appeared!")).toEqual(25); -}); - -test("multiply multiplies numbers", () => { - expect(multiply(2, 3, 6)).toEqual(36); -}); - -test("multiply multiplies different numbers", () => { - expect(multiply(2, 3, 4)).toEqual(24); -}); +// The syntax for this function is valid but it has an error, find it and fix it. + +function wordtrim(str) { + return str.trim(); +} +function trimWord(word) { + return wordtrim(word); +} + +function getStringLength(word) { + return word.length; +} + +function multiply(a, b, c) { + return a * b * c; +} + +/* +=================================================== +======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== + +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 2-logic-error` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +=================================================== +*/ + +test("trimWord trims leading and trailing whitespace", () => { + expect(trimWord(" CodeYourFuture ")).toEqual("CodeYourFuture"); +}); + +test("trimWord doesn't remove whitespace in the middle of the string", () => { + expect(trimWord(" CodeYourFuture teaches coding ")).toEqual( + "CodeYourFuture teaches coding" + ); +}); + +test("getStringLength returns the length of a word", () => { + expect(getStringLength("Turtles")).toEqual(7); +}); + +test("getStringLength returns the length of a sentence", () => { + expect(getStringLength("A wild sentence appeared!")).toEqual(25); +}); + +test("multiply multiplies numbers", () => { + expect(multiply(2, 3, 6)).toEqual(36); +}); + +test("multiply multiplies different numbers", () => { + expect(multiply(2, 3, 4)).toEqual(24); +}); diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 9a488be89..358942d9f 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,42 +1,42 @@ -// Add comments to explain what this function does. You're meant to use Google! - -function getRandomNumber() { - return Math.random() * 10; - //random returns with 10 will result in a max value of 9.999 and the lowest value is 0 -} - -// Add comments to explain what this function does. You're meant to use Google! -function combine2Words(word1, word2) { - return word1.concat(word2); - // join word1 to word2 together as a string. - //Concatenation is the process of appending one string to the end of another 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} ${secondWord} ${thirdWord}`; -} - -/* -=================================================== -======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== - -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 3-function-output` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -================================== -*/ - -test("concatenate example #1", () => { - expect(concatenate("code", "your", "future")).toEqual("code your future"); -}); - -test("concatenate example #2", () => { - expect(concatenate("I", "like", "pizza")).toEqual("I like pizza"); -}); - -test("concatenate doesn't only accept strings", () => { - expect(concatenate("I", "am", 13)).toEqual("I am 13"); -}); +// Add comments to explain what this function does. You're meant to use Google! + +function getRandomNumber() { + return Math.random() * 10; + //random returns with 10 will result in a max value of 9.999 and the lowest value is 0 +} + +// Add comments to explain what this function does. You're meant to use Google! +function combine2Words(word1, word2) { + return word1.concat(word2); + // join word1 to word2 together as a string. + //Concatenation is the process of appending one string to the end of another 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} ${secondWord} ${thirdWord}`; +} + +/* +=================================================== +======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== + +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 3-function-output` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +================================== +*/ + +test("concatenate example #1", () => { + expect(concatenate("code", "your", "future")).toEqual("code your future"); +}); + +test("concatenate example #2", () => { + expect(concatenate("I", "like", "pizza")).toEqual("I like pizza"); +}); + +test("concatenate doesn't only accept strings", () => { + expect(concatenate("I", "am", 13)).toEqual("I am 13"); +}); diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index 0eb595efe..427b6776f 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -1,62 +1,62 @@ -/* - SALES TAX - ========= - A business requires a program that calculates how much the price of a product is including sales tax - Sales tax is 20% of the price of the product. -*/ - -function calculateSalesTax(price) { - let taxOf = (price * 20) / 100; - return taxOf + price; -} - -/* - CURRENCY FORMATTING - =================== - The business has informed you that prices must have 2 decimal places - They must also start with the currency symbol - Write a function that adds tax to a number, and then transforms the total into the format £0.00 - - Remember that the prices must include the sales tax (hint: you already wrote a function for this!) -*/ - -function addTaxAndFormatCurrency(price) { - let taxOf = (price * 20) / 100; - let total = taxOf + price; - return `£${total.toFixed(2)}`; -} - -/* -=================================================== -======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== - -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 4-tax` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -=================================================== -*/ - -test("calculateSalesTax for £15", () => { - expect(calculateSalesTax(15)).toEqual(18); -}); - -test("calculateSalesTax for £17.50", () => { - expect(calculateSalesTax(17.5)).toEqual(21); -}); - -test("calculateSalesTax for £34", () => { - expect(calculateSalesTax(34)).toEqual(40.8); -}); - -test("addTaxAndFormatCurrency for £15", () => { - expect(addTaxAndFormatCurrency(15)).toEqual("£18.00"); -}); - -test("addTaxAndFormatCurrency for £17.50", () => { - expect(addTaxAndFormatCurrency(17.5)).toEqual("£21.00"); -}); - -test("addTaxAndFormatCurrency for £34", () => { - expect(addTaxAndFormatCurrency(34)).toEqual("£40.80"); -}); +/* + SALES TAX + ========= + A business requires a program that calculates how much the price of a product is including sales tax + Sales tax is 20% of the price of the product. +*/ + +function calculateSalesTax(price) { + let taxOf = (price * 20) / 100; + return taxOf + price; +} + +/* + CURRENCY FORMATTING + =================== + The business has informed you that prices must have 2 decimal places + They must also start with the currency symbol + Write a function that adds tax to a number, and then transforms the total into the format £0.00 + + Remember that the prices must include the sales tax (hint: you already wrote a function for this!) +*/ + +function addTaxAndFormatCurrency(price) { + let taxOf = (price * 20) / 100; + let total = taxOf + price; + return `£${total.toFixed(2)}`; +} + +/* +=================================================== +======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== + +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 4-tax` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +=================================================== +*/ + +test("calculateSalesTax for £15", () => { + expect(calculateSalesTax(15)).toEqual(18); +}); + +test("calculateSalesTax for £17.50", () => { + expect(calculateSalesTax(17.5)).toEqual(21); +}); + +test("calculateSalesTax for £34", () => { + expect(calculateSalesTax(34)).toEqual(40.8); +}); + +test("addTaxAndFormatCurrency for £15", () => { + expect(addTaxAndFormatCurrency(15)).toEqual("£18.00"); +}); + +test("addTaxAndFormatCurrency for £17.50", () => { + expect(addTaxAndFormatCurrency(17.5)).toEqual("£21.00"); +}); + +test("addTaxAndFormatCurrency for £34", () => { + expect(addTaxAndFormatCurrency(34)).toEqual("£40.80"); +}); diff --git a/package.json b/package.json index 93e0861e3..73e79da92 100644 --- a/package.json +++ b/package.json @@ -1,34 +1,34 @@ -{ - "name": "javascript-core-1-coursework-week1", - "version": "1.0.0", - "description": "Exercises for JS1 Week 1", - "license": "CC-BY-SA-4.0", - "scripts": { - "test": "jest" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1.git" - }, - "bugs": { - "url": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/issues" - }, - "jest": { - "setupFilesAfterEnv": ["jest-extended"], - "projects": [ - { - "displayName": "mandatory", - "testMatch": ["/mandatory/*.js"] - }, - { - "displayName": "extra", - "testMatch": ["/extra/*.js"] - } - ] - }, - "homepage": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1#readme", - "devDependencies": { - "jest": "^26.6.3", - "jest-extended": "^0.11.5" - } -} +{ + "name": "javascript-core-1-coursework-week1", + "version": "1.0.0", + "description": "Exercises for JS1 Week 1", + "license": "CC-BY-SA-4.0", + "scripts": { + "test": "jest" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1.git" + }, + "bugs": { + "url": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/issues" + }, + "jest": { + "setupFilesAfterEnv": ["jest-extended"], + "projects": [ + { + "displayName": "mandatory", + "testMatch": ["/mandatory/*.js"] + }, + { + "displayName": "extra", + "testMatch": ["/extra/*.js"] + } + ] + }, + "homepage": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1#readme", + "devDependencies": { + "jest": "^26.6.3", + "jest-extended": "^0.11.5" + } +}