diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index ae4e1977..9b9cc912 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -20,7 +20,7 @@ Self checklist - [ ] I have committed my files one by one, on purpose, and for a reason - [ ] I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK - [ ] I have tested my changes -- [ ] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/contributing/) +- [ ] My changes follow the [style guide](https://syllabus.codeyourfuture.io/guides/code-style-guide/) - [ ] My changes meet the [requirements](./README.md) of this task ## Changelist diff --git a/Sprint-2/debug/0.js b/Sprint-2/debug/0.js index b46d471a..279c3be5 100644 --- a/Sprint-2/debug/0.js +++ b/Sprint-2/debug/0.js @@ -1,4 +1,5 @@ // Predict and explain first... +// Prediction : I think the function won't return anything because it's using console.log() and not return. function multiply(a, b) { console.log(a * b); diff --git a/Sprint-2/debug/1.js b/Sprint-2/debug/1.js index df4020ca..15081715 100644 --- a/Sprint-2/debug/1.js +++ b/Sprint-2/debug/1.js @@ -1,4 +1,5 @@ // Predict and explain first... +// Prediction : it will return "the sum of 10 and 32 is null". Because the function returns something but it's null. function sum(a, b) { return; @@ -6,3 +7,13 @@ function sum(a, b) { } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +// The result of summing 10 and 32 is 320 + +// Predict and explain first... + +function sum(a, b) { + return; + a + b; +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); \ No newline at end of file diff --git a/Sprint-2/debug/2.js b/Sprint-2/debug/2.js index bae9652a..639c4b76 100644 --- a/Sprint-2/debug/2.js +++ b/Sprint-2/debug/2.js @@ -11,4 +11,4 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`); console.log(`The last digit of 806 is ${getLastDigit(806)}`); // This program should tell the user the last digit of each number. -// Explain why getLastDigit is not working properly - correct the problem +// Explain why getLastDigit is not working properly - correct the problem \ No newline at end of file diff --git a/Sprint-2/errors/0.js b/Sprint-2/errors/0.js index 74640e11..06c7231d 100644 --- a/Sprint-2/errors/0.js +++ b/Sprint-2/errors/0.js @@ -3,7 +3,8 @@ // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring + function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; + str = `${str[0].toUpperCase()}${str.slice(1)}`; // No `let`, just reassign return str; } diff --git a/Sprint-2/errors/1.js b/Sprint-2/errors/1.js index 4602ed23..bf588eac 100644 --- a/Sprint-2/errors/1.js +++ b/Sprint-2/errors/1.js @@ -4,10 +4,8 @@ // Try playing computer with the example to work out what is going on function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; - return percentage; } -console.log(decimalNumber); +console.log(convertToPercentage(0.5)); // Outputs "50%" diff --git a/Sprint-2/errors/2.js b/Sprint-2/errors/2.js index 814334d9..177cf5cc 100644 --- a/Sprint-2/errors/2.js +++ b/Sprint-2/errors/2.js @@ -1,10 +1,8 @@ -// Predict and explain first... - -// this function should square any number but instead we're going to get an error - -function square(3) { +function square(num) { return num * num; } +console.log(square(3)); // Outputs: 9 + diff --git a/Sprint-2/extend/format-time.js b/Sprint-2/extend/format-time.js index f3b83062..afa812c3 100644 --- a/Sprint-2/extend/format-time.js +++ b/Sprint-2/extend/format-time.js @@ -22,3 +22,21 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const tests = [ + { input: "08:00", expected: "08:00 am" }, + { input: "23:00", expected: "11:00 pm" }, + { input: "00:00", expected: "12:00 am" }, + { input: "12:00", expected: "12:00 pm" }, + { input: "00:01", expected: "12:01 am" }, + { input: "12:01", expected: "12:01 pm" }, + { input: "13:00", expected: "1:00 pm" }, +]; + +tests.forEach(({ input, expected }) => { + const output = formatAs12HourClock(input); + console.assert( + output === expected, + `Test failed for input "${input}". Output: "${output}", Expected: "${expected}"` + ); +}); diff --git a/Sprint-2/implement/bmi.js b/Sprint-2/implement/bmi.js index 259f62d4..eaeff214 100644 --- a/Sprint-2/implement/bmi.js +++ b/Sprint-2/implement/bmi.js @@ -13,3 +13,16 @@ // Given someone's weight in kg and height in metres // Then when we call this function with the weight and height // It should return their Body Mass Index to 1 decimal place + + +function calculateBMI(weight, height) { + // Step 1: Square the height + const heightSquared = height ** 2; + + // Step 2: Divide weight by height squared + const bmi = weight / heightSquared; + + // Step 3: Return the result to 1 decimal place + return parseFloat(bmi.toFixed(1)); + } + \ No newline at end of file diff --git a/Sprint-2/implement/cases.js b/Sprint-2/implement/cases.js index 9e56a27b..a8f8e4fb 100644 --- a/Sprint-2/implement/cases.js +++ b/Sprint-2/implement/cases.js @@ -13,3 +13,16 @@ // You will need to come up with an appropriate name for the function // Use the string documentation to help you find a solution + + +function toUpperSnakeCase(input) { + // Step 1: Replace spaces with underscores + const snakeCase = input.replace(/ /g, "_"); + + // Step 2: Convert the string to uppercase + const upperSnakeCase = snakeCase.toUpperCase(); + + // Step 3: Return the result + return upperSnakeCase; + } + \ No newline at end of file diff --git a/Sprint-2/implement/to-pounds.js b/Sprint-2/implement/to-pounds.js index 6265a1a7..a0f98fca 100644 --- a/Sprint-2/implement/to-pounds.js +++ b/Sprint-2/implement/to-pounds.js @@ -4,3 +4,13 @@ // You will need to declare a function called toPounds with an appropriately named parameter. // You should call this function a number of times to check it works for different inputs + + +function toPounds(kilograms) { + // Convert kilograms to pounds (1 kg = 2.20462 pounds) + const pounds = kilograms * 2.20462; + + // Return the result, rounded to 2 decimal places + return parseFloat(pounds.toFixed(2)); + } + \ No newline at end of file diff --git a/Sprint-2/implement/vat.js b/Sprint-2/implement/vat.js index 3fb16722..8647ce5c 100644 --- a/Sprint-2/implement/vat.js +++ b/Sprint-2/implement/vat.js @@ -8,3 +8,13 @@ // Given a number, // When I call this function with a number // it returns the new price with VAT added on + + +function addVAT(price) { + // Multiply the price by 1.2 to add 20% VAT + const vatInclusivePrice = price * 1.2; + + // Return the result, rounded to 2 decimal places + return parseFloat(vatInclusivePrice.toFixed(2)); + } + diff --git a/Sprint-2/interpret/time-format.js b/Sprint-2/interpret/time-format.js index c5a0c161..b2e9615c 100644 --- a/Sprint-2/interpret/time-format.js +++ b/Sprint-2/interpret/time-format.js @@ -29,3 +29,6 @@ function formatTimeDisplay(seconds) { // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer + + +return `${pad(0)}:${pad(1)}:${pad(1)}`; // "00:01:01"