From bb0d4e974b1e636621b12e2fc081688b225a23e3 Mon Sep 17 00:00:00 2001 From: Gai <146184211+gai93003@users.noreply.github.com> Date: Mon, 28 Oct 2024 18:44:01 +0000 Subject: [PATCH 01/13] The error was a hosting error which i have corrected. --- Sprint-1/errors/2.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/errors/2.js b/Sprint-1/errors/2.js index e09b89831..0e52ca5be 100644 --- a/Sprint-1/errors/2.js +++ b/Sprint-1/errors/2.js @@ -1,5 +1,9 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? -console.log(`I was born in ${cityOfBirth}`); + const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + + +//This is a hosting error. You can't use a variable before declaring it. I have made some changes on how I believe it should be. \ No newline at end of file From e328f4f8ce95db5345d90b4d23e91ace97b6ea36 Mon Sep 17 00:00:00 2001 From: Gai <146184211+gai93003@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:30:20 +0000 Subject: [PATCH 02/13] Line 3 is about an assignment operator. --- Sprint-1/exercises/count.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/exercises/count.js b/Sprint-1/exercises/count.js index 117bcb2b6..125d5aa4f 100644 --- a/Sprint-1/exercises/count.js +++ b/Sprint-1/exercises/count.js @@ -4,3 +4,5 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing + +//Line 3 is about an assignment operator used to increase the count variable by 1. \ No newline at end of file From 8db87e96716c41479b1fa5ceb53527a7544eac6d Mon Sep 17 00:00:00 2001 From: Gai <146184211+gai93003@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:32:41 +0000 Subject: [PATCH 03/13] The code is correct. --- Sprint-1/errors/3.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/errors/3.js b/Sprint-1/errors/3.js index ec101884d..eff15b63d 100644 --- a/Sprint-1/errors/3.js +++ b/Sprint-1/errors/3.js @@ -7,3 +7,6 @@ const last4Digits = cardNumber.slice(-4); // Then run the code and see what error it gives. // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value + + +// I believe the the code is correct. However, the first variable is considered as a string. If operation were to be done on it, the output should first be converted into an integer. \ No newline at end of file From 4897e39898d7757fa208a046b8028a67764cc8c9 Mon Sep 17 00:00:00 2001 From: Gai <146184211+gai93003@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:35:31 +0000 Subject: [PATCH 04/13] Variable names can't start with numbers or contain reserved names. --- Sprint-1/errors/4.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-1/errors/4.js b/Sprint-1/errors/4.js index 21dad8c5d..10686f4ed 100644 --- a/Sprint-1/errors/4.js +++ b/Sprint-1/errors/4.js @@ -1,2 +1,4 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const HourClockTime = "20:53"; +const hourClockTime = "08:53"; + +// This is a wrong declaration syntax, variables can't start with numbers, special characters or contain reserved words. \ No newline at end of file From 058e7923d2929e6ba358cab3861c913f40d592f4 Mon Sep 17 00:00:00 2001 From: Gai <146184211+gai93003@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:10:25 +0000 Subject: [PATCH 05/13] I have created the three variables, wholeNumberPart, decimalPart and roundedNum --- Sprint-1/exercises/decimal.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-1/exercises/decimal.js b/Sprint-1/exercises/decimal.js index cc5947ce2..80b854c21 100644 --- a/Sprint-1/exercises/decimal.js +++ b/Sprint-1/exercises/decimal.js @@ -1,5 +1,9 @@ const num = 56.5678; +const wholeNumberPart = Math.floor(num); +const decimalPart = (num % 1).toFixed(4); +const roundedNum = Math.round(num); + // You should look up Math functions for this exercise https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math // Create a variable called wholeNumberPart and assign to it an expression that evaluates to 56 ( the whole number part of num ) From ada4d4d3b7817ce962a8da3cf1d6d5757eaf9adf Mon Sep 17 00:00:00 2001 From: Gai <146184211+gai93003@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:36:46 +0000 Subject: [PATCH 06/13] I accessed the first character by indexing. The first initials are then put together by using addition operator --- Sprint-1/exercises/initials.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/exercises/initials.js b/Sprint-1/exercises/initials.js index 6b80cd137..42e35acec 100644 --- a/Sprint-1/exercises/initials.js +++ b/Sprint-1/exercises/initials.js @@ -2,5 +2,7 @@ let firstName = "Creola"; let middleName = "Katherine"; let lastName = "Johnson"; +const initials = firstName[0] + middleName[0] + lastName[0] + // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. From 83891e4b45fe71402013ec02bffb0d5dad12b577 Mon Sep 17 00:00:00 2001 From: Gai <146184211+gai93003@users.noreply.github.com> Date: Tue, 29 Oct 2024 22:26:46 +0000 Subject: [PATCH 07/13] I used the slice to find the dir from the first character to the the lastSlashIndex --- Sprint-1/exercises/paths.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/exercises/paths.js b/Sprint-1/exercises/paths.js index c91cd2ab3..6bd58ef0e 100644 --- a/Sprint-1/exercises/paths.js +++ b/Sprint-1/exercises/paths.js @@ -16,3 +16,6 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable + + +const dir = filePath.slice(0, lastSlashIndex); From 4a3908be1ec61469d283ab5161808cc6206619ac Mon Sep 17 00:00:00 2001 From: Gai <146184211+gai93003@users.noreply.github.com> Date: Tue, 29 Oct 2024 22:44:33 +0000 Subject: [PATCH 08/13] I used slice method to find the occurance of '.' and then add 1 to find the next value to it. --- Sprint-1/exercises/paths.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/exercises/paths.js b/Sprint-1/exercises/paths.js index 6bd58ef0e..324ef2f41 100644 --- a/Sprint-1/exercises/paths.js +++ b/Sprint-1/exercises/paths.js @@ -19,3 +19,4 @@ console.log(`The base part of ${filePath} is ${base}`); const dir = filePath.slice(0, lastSlashIndex); +const ext = base.slice(base.lastIndexOf(".") + 1); From 992c112d2c68dc3771e3bae922df487d006be7f2 Mon Sep 17 00:00:00 2001 From: Gai <146184211+gai93003@users.noreply.github.com> Date: Thu, 31 Oct 2024 22:24:34 +0000 Subject: [PATCH 09/13] I used toString method on the cardNumber to turn it into strings and then used slice to retrieve the last 4 digits --- Sprint-1/errors/3.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/errors/3.js b/Sprint-1/errors/3.js index eff15b63d..e11458c5c 100644 --- a/Sprint-1/errors/3.js +++ b/Sprint-1/errors/3.js @@ -1,4 +1,5 @@ const cardNumber = 4533787178994213; +cardNumber = cardNumber.toString(); const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber @@ -9,4 +10,6 @@ const last4Digits = cardNumber.slice(-4); // Then try updating the expression last4Digits is assigned to, in order to get the correct value -// I believe the the code is correct. However, the first variable is considered as a string. If operation were to be done on it, the output should first be converted into an integer. \ No newline at end of file +// I believe the the code is correct. However, the first variable is considered as a string. If operation were to be done on it, the output should first be converted into an integer. + +//I used toString method on the cardNumber to turn it into strings and then use slice to retrieve the last 4 digits. \ No newline at end of file From ca90c22c5f03c4d5c5f243984cc70f727d28cb64 Mon Sep 17 00:00:00 2001 From: Gai <146184211+gai93003@users.noreply.github.com> Date: Thu, 31 Oct 2024 22:34:30 +0000 Subject: [PATCH 10/13] The variable names were not descriptive enough. --- Sprint-1/errors/4.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sprint-1/errors/4.js b/Sprint-1/errors/4.js index 10686f4ed..a9d065129 100644 --- a/Sprint-1/errors/4.js +++ b/Sprint-1/errors/4.js @@ -1,4 +1,6 @@ -const HourClockTime = "20:53"; -const hourClockTime = "08:53"; +const twenty4HourClockTime = "20:53"; +const twelveHourClockTime = "08:53"; -// This is a wrong declaration syntax, variables can't start with numbers, special characters or contain reserved words. \ No newline at end of file +// This is a wrong declaration syntax, variables can't start with numbers, special characters or contain reserved words. + +//I neglect that fact the two variables have the same names since Javascript variable names are not \ No newline at end of file From a16785e69d2ff21bc5ef7c4b6a900fed7ca31555 Mon Sep 17 00:00:00 2001 From: Gai <146184211+gai93003@users.noreply.github.com> Date: Fri, 1 Nov 2024 23:15:49 +0000 Subject: [PATCH 11/13] I created a new variable to store the strings created from the cardNumber --- Sprint-1/errors/3.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sprint-1/errors/3.js b/Sprint-1/errors/3.js index e11458c5c..8532e4027 100644 --- a/Sprint-1/errors/3.js +++ b/Sprint-1/errors/3.js @@ -1,6 +1,6 @@ const cardNumber = 4533787178994213; -cardNumber = cardNumber.toString(); -const last4Digits = cardNumber.slice(-4); +const cardNumberStrings = cardNumber.toString(); +const last4Digits = cardNumberStrings.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -12,4 +12,6 @@ const last4Digits = cardNumber.slice(-4); // I believe the the code is correct. However, the first variable is considered as a string. If operation were to be done on it, the output should first be converted into an integer. -//I used toString method on the cardNumber to turn it into strings and then use slice to retrieve the last 4 digits. \ No newline at end of file +//I used toString method on the cardNumber to turn it into strings and then use slice to retrieve the last 4 digits. + +// I converted the cardNumber integers into a string and assigned them to a variable called cardNumberStrings, this way, I can continue using the 'const' declaration instead of using the 'let' \ No newline at end of file From 00e0ba92b2a5b1e78df7b48341f805ecb78c1924 Mon Sep 17 00:00:00 2001 From: Gai <146184211+gai93003@users.noreply.github.com> Date: Wed, 6 Nov 2024 16:28:59 +0000 Subject: [PATCH 12/13] I corrected a bug inorder to get the last character in a variable of numbers converted to strings --- Sprint-2/debug/2.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/debug/2.js b/Sprint-2/debug/2.js index bae9652a8..a152e263c 100644 --- a/Sprint-2/debug/2.js +++ b/Sprint-2/debug/2.js @@ -3,7 +3,7 @@ const num = 103; function getLastDigit() { - return num.toString().slice(-1); + return num.toString().slice(num.length - 1); } console.log(`The last digit of 42 is ${getLastDigit(42)}`); @@ -12,3 +12,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 + +//Using slice(-1) is not a feasible method to use in this case. The correct way to do the code is by using num.toString().slice(num.length - 1) \ No newline at end of file From 56bbf5894bc1645dca9bb9960be1cdecd829487f Mon Sep 17 00:00:00 2001 From: Gai <146184211+gai93003@users.noreply.github.com> Date: Sat, 16 Nov 2024 00:21:31 +0000 Subject: [PATCH 13/13] I attempted the exercises in sprint 2 --- Sprint-2/debug/0.js | 5 ++++- Sprint-2/debug/1.js | 5 +++-- Sprint-2/errors/0.js | 5 +++++ Sprint-2/errors/1.js | 7 +++++-- Sprint-2/errors/2.js | 3 ++- Sprint-2/extend/format-time.js | 21 +++++++++++++++++++++ Sprint-2/implement/bmi.js | 6 ++++++ Sprint-2/implement/cases.js | 10 ++++++++++ Sprint-2/implement/to-pounds.js | 18 ++++++++++++++++++ Sprint-2/implement/vat.js | 6 ++++++ Sprint-2/interpret/time-format.js | 5 +++++ 11 files changed, 85 insertions(+), 6 deletions(-) diff --git a/Sprint-2/debug/0.js b/Sprint-2/debug/0.js index b46d471a8..24d2a0689 100644 --- a/Sprint-2/debug/0.js +++ b/Sprint-2/debug/0.js @@ -1,7 +1,10 @@ // Predict and explain first... function multiply(a, b) { - console.log(a * b); + return a * b; + // console.log(a * b); } console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); + +// The function returns undefined but it will log the product of the inputs to the console tab. \ No newline at end of file diff --git a/Sprint-2/debug/1.js b/Sprint-2/debug/1.js index df4020cae..31a6c7b60 100644 --- a/Sprint-2/debug/1.js +++ b/Sprint-2/debug/1.js @@ -1,8 +1,9 @@ // Predict and explain first... function sum(a, b) { - return; - a + b; + return a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); + +//The function returns undefined since the value has not been assigned to it. \ No newline at end of file diff --git a/Sprint-2/errors/0.js b/Sprint-2/errors/0.js index 74640e118..7af3d1d0e 100644 --- a/Sprint-2/errors/0.js +++ b/Sprint-2/errors/0.js @@ -7,3 +7,8 @@ function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } + + +capitalise('hello world') + +// This function is intended to get the first character in a string entered. \ No newline at end of file diff --git a/Sprint-2/errors/1.js b/Sprint-2/errors/1.js index 4602ed237..e3bb2884a 100644 --- a/Sprint-2/errors/1.js +++ b/Sprint-2/errors/1.js @@ -4,10 +4,13 @@ // Try playing computer with the example to work out what is going on function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; + // const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(decimalNumber); +console.log(convertToPercentage(0.5)); + + +// The function won't work because variable name declared cannot be used since it is used as a parameter. \ No newline at end of file diff --git a/Sprint-2/errors/2.js b/Sprint-2/errors/2.js index 814334d9e..d46622e06 100644 --- a/Sprint-2/errors/2.js +++ b/Sprint-2/errors/2.js @@ -3,8 +3,9 @@ // this function should square any number but instead we're going to get an error -function square(3) { +function square(num) { return num * num; } +// This function will return a syntax error because a number is used instead of a parameter. The correct function declaration should have a parameter instead of a value. \ No newline at end of file diff --git a/Sprint-2/extend/format-time.js b/Sprint-2/extend/format-time.js index f3b83062d..815e1cb65 100644 --- a/Sprint-2/extend/format-time.js +++ b/Sprint-2/extend/format-time.js @@ -22,3 +22,24 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const currentOutput3 = formatAs12HourClock("16:00"); +const targetOutput3 = "4:00 pm"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}` +) + +const currentOutput4 = formatAs12HourClock("19:00"); +const targetOutput4 = "7:00 pm"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}` +) + +const currentOutput5 = formatAs12HourClock("20:00"); +const targetOutput5 = "8:00 pm"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}` +) \ No newline at end of file diff --git a/Sprint-2/implement/bmi.js b/Sprint-2/implement/bmi.js index 259f62d48..21c75d90d 100644 --- a/Sprint-2/implement/bmi.js +++ b/Sprint-2/implement/bmi.js @@ -13,3 +13,9 @@ // 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 + +const findBMI = (weight, height) => { + return (weight / (height ** 2)).toFixed(1); +} + +findBMI(70, 1.73); \ No newline at end of file diff --git a/Sprint-2/implement/cases.js b/Sprint-2/implement/cases.js index 9e56a27b6..7a7d8556f 100644 --- a/Sprint-2/implement/cases.js +++ b/Sprint-2/implement/cases.js @@ -13,3 +13,13 @@ // You will need to come up with an appropriate name for the function // Use the string documentation to help you find a solution + +const upperSnakeCase = (input) => { + for ( let i = 0; i < input.length; i++) { + + } + const upperCase = input.replace(/\s+/g, '_').toUpperCase(); + console.log(upperCase) +} + +upperSnakeCase('lords of the rings'); \ No newline at end of file diff --git a/Sprint-2/implement/to-pounds.js b/Sprint-2/implement/to-pounds.js index 6265a1a70..ddce0849f 100644 --- a/Sprint-2/implement/to-pounds.js +++ b/Sprint-2/implement/to-pounds.js @@ -4,3 +4,21 @@ // 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 + +const toPounds = (penceString) => { + const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1 +); + +const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 +); +const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + +console.log(`£${pounds}.${pence}`); +} + +toPounds('3455p'); \ No newline at end of file diff --git a/Sprint-2/implement/vat.js b/Sprint-2/implement/vat.js index 3fb167226..6872d3982 100644 --- a/Sprint-2/implement/vat.js +++ b/Sprint-2/implement/vat.js @@ -8,3 +8,9 @@ // Given a number, // When I call this function with a number // it returns the new price with VAT added on + +const calcualteVat = (price) => { + return `£${price * 1.2}`; +} + +calcualteVat(60); \ No newline at end of file diff --git a/Sprint-2/interpret/time-format.js b/Sprint-2/interpret/time-format.js index c5a0c1619..5d12cdd33 100644 --- a/Sprint-2/interpret/time-format.js +++ b/Sprint-2/interpret/time-format.js @@ -19,13 +19,18 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? + // ~ pad function will also be called three times. // Call formatTimeDisplay with an input of 61, now answer the following: // b) What is the value assigned to num when pad is called for the first time? + // ~ The value assigned to num will be the argument value 61 // c) What is the return value of pad is called for the first time? + // ~ The return value will be '01' // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer + // ~ The return value is 1 because the seconds input will subtract the remainingSeconds which is 1 and then divide the resultant value by 60, so the answer will give 1. // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer + // ~ The return value is '01' because it will be calculating the remaining seconds which is 1 and as such the pad method will add 0 to it.