From f708d7efb4022f7249992c6eb9c61f30e46d7905 Mon Sep 17 00:00:00 2001 From: loveth900 Date: Mon, 25 Nov 2024 16:39:42 +0000 Subject: [PATCH 01/15] the prediction was done --- Sprint-2/debug/0.js | 1 + 1 file changed, 1 insertion(+) 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); From fe5755d0a157f94ac4bebce735adbd93e0759a92 Mon Sep 17 00:00:00 2001 From: loveth900 Date: Mon, 25 Nov 2024 16:51:24 +0000 Subject: [PATCH 02/15] the sum is null --- Sprint-2/debug/1.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-2/debug/1.js b/Sprint-2/debug/1.js index df4020ca..aacf8ed8 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,4 @@ 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 \ No newline at end of file From e1bd38e38328df1e312f4cf63f7ba87bc18a4d35 Mon Sep 17 00:00:00 2001 From: loveth900 Date: Mon, 25 Nov 2024 18:00:41 +0000 Subject: [PATCH 03/15] the log is always three --- Sprint-2/debug/2.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-2/debug/2.js b/Sprint-2/debug/2.js index bae9652a..b32aad4b 100644 --- a/Sprint-2/debug/2.js +++ b/Sprint-2/debug/2.js @@ -1,8 +1,10 @@ // Predict and explain first... +// Prediction : num is defined with const. All of these console.log()s will return to"3". -const num = 103; +let num = 103; function getLastDigit() { +function getLastDigit(num) { return num.toString().slice(-1); } @@ -12,3 +14,5 @@ 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 + +//I had to make a parameter for the function to take in instead of having a constant value that it uses, I made the const let and I added the parameter num to the getLast Digit Function. \ No newline at end of file From ae1b7d904229f4391622705cb5e19f86e4fd0e40 Mon Sep 17 00:00:00 2001 From: loveth900 Date: Mon, 25 Nov 2024 16:51:24 +0000 Subject: [PATCH 04/15] the sum is null --- .github/pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 86371c15e6e3995aef86e232e4ce767d6a0a71aa Mon Sep 17 00:00:00 2001 From: loveth900 Date: Tue, 10 Dec 2024 13:54:41 +0000 Subject: [PATCH 05/15] done with prediction --- Sprint-2/debug/1.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sprint-2/debug/1.js b/Sprint-2/debug/1.js index aacf8ed8..15081715 100644 --- a/Sprint-2/debug/1.js +++ b/Sprint-2/debug/1.js @@ -7,4 +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 \ No newline at end of file +// 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 From 5b70c0b146f294d60770ad06780cea875b5aa53a Mon Sep 17 00:00:00 2001 From: loveth900 Date: Tue, 10 Dec 2024 13:58:23 +0000 Subject: [PATCH 06/15] it was predicted with the last digit --- Sprint-2/debug/2.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Sprint-2/debug/2.js b/Sprint-2/debug/2.js index b32aad4b..639c4b76 100644 --- a/Sprint-2/debug/2.js +++ b/Sprint-2/debug/2.js @@ -1,10 +1,8 @@ // Predict and explain first... -// Prediction : num is defined with const. All of these console.log()s will return to"3". -let num = 103; +const num = 103; function getLastDigit() { -function getLastDigit(num) { return num.toString().slice(-1); } @@ -13,6 +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 - -//I had to make a parameter for the function to take in instead of having a constant value that it uses, I made the const let and I added the parameter num to the getLast Digit Function. \ No newline at end of file +// Explain why getLastDigit is not working properly - correct the problem \ No newline at end of file From 6e096049822a7ef4c522f85af4297eaa6b770250 Mon Sep 17 00:00:00 2001 From: loveth900 Date: Tue, 10 Dec 2024 14:12:27 +0000 Subject: [PATCH 07/15] error because the variable str --- Sprint-2/errors/0.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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; } From dcd0dc63878866b449c7974d87c8b25ec0d5c1e9 Mon Sep 17 00:00:00 2001 From: loveth900 Date: Tue, 10 Dec 2024 14:16:31 +0000 Subject: [PATCH 08/15] redeclaration of decimalNumber --- Sprint-2/errors/1.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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%" From 2633c5179d31c605376483307796bf7aff1975c2 Mon Sep 17 00:00:00 2001 From: loveth900 Date: Tue, 10 Dec 2024 14:19:33 +0000 Subject: [PATCH 09/15] function square(3) --- Sprint-2/errors/2.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 + From 318675e414a6c27459ec6c0f6f4b59c0267a9520 Mon Sep 17 00:00:00 2001 From: loveth900 Date: Tue, 10 Dec 2024 14:27:07 +0000 Subject: [PATCH 10/15] Incorrect handling of times --- Sprint-2/extend/format-time.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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}"` + ); +}); From b93c089978f5f50248f3a58cbea211377dabdc6c Mon Sep 17 00:00:00 2001 From: loveth900 Date: Tue, 10 Dec 2024 14:35:37 +0000 Subject: [PATCH 11/15] the result was accurate --- Sprint-2/implement/bmi.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 From 3f0cc1290196009c70a2db9b943edb5b4c5d6ce8 Mon Sep 17 00:00:00 2001 From: loveth900 Date: Tue, 10 Dec 2024 14:39:14 +0000 Subject: [PATCH 12/15] UPPER_SNAKE_CASE IMPLEMENTATION --- Sprint-2/implement/cases.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 From da91ca62701a20f7609f2cae0ba1770efcbef272 Mon Sep 17 00:00:00 2001 From: loveth900 Date: Tue, 10 Dec 2024 14:45:07 +0000 Subject: [PATCH 13/15] create a reusable function --- Sprint-2/implement/to-pounds.js | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 From c6a176c91eaf33e7fdd357c33e1a2712b7541fd8 Mon Sep 17 00:00:00 2001 From: loveth900 Date: Tue, 10 Dec 2024 14:47:29 +0000 Subject: [PATCH 14/15] it was in a round number --- Sprint-2/implement/vat.js | 10 ++++++++++ 1 file changed, 10 insertions(+) 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)); + } + From 5997920c2348767f1f5a6ce9243327925504a3d8 Mon Sep 17 00:00:00 2001 From: loveth900 Date: Tue, 10 Dec 2024 14:59:59 +0000 Subject: [PATCH 15/15] the return of the varibles were given --- Sprint-2/interpret/time-format.js | 3 +++ 1 file changed, 3 insertions(+) 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"