From ebed26dd7b081f4c853587aa22b2b4a217d33021 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 7 Feb 2026 16:05:16 +0000 Subject: [PATCH 1/4] solved first error --- Sprint-1/2-mandatory-errors/0.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..6a7a7f690 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,2 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +// This is just an instruction for the first activity - but it is just for human consumption +// We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file From ffebd9e98b1a50b07c07245f17032009a673326d Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 10 Feb 2026 14:48:48 +0000 Subject: [PATCH 2/4] sprint 2/1 compleat --- Sprint-1/2-mandatory-errors/0.js | 4 ++-- Sprint-1/2-mandatory-errors/1.js | 3 ++- .../3-mandatory-interpret/1-percentage-change.js | 2 +- Sprint-2/1-key-errors/0.js | 16 +++++++++++++--- Sprint-2/1-key-errors/1.js | 13 +++++++++++-- Sprint-2/1-key-errors/2.js | 16 +++++++++++++--- 6 files changed, 42 insertions(+), 12 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index 6a7a7f690..cf6c5039f 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,2 @@ -// This is just an instruction for the first activity - but it is just for human consumption -// We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +This is just an instruction for the first activity - but it is just for human consumption +We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..c38f66431 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,5 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; +console.log (age) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..85056b50e 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..b9e0d1397 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,23 @@ // Predict and explain first... // =============> write your prediction here +// you will get an error becuase srt has alredy been declared + // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring -function capitalise(str) { +/*function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; -} + return str;*/ + // =============> write your explanation here +//let str = `${str[0].toUpperCase()}${str.slice(1)}`; + // ^ + +//SyntaxError: Identifier 'str' has already been declared // =============> write your new code here +function capitalise(str) { + let strTwo = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} \ No newline at end of file diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..d631960ac 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,29 @@ // Predict and explain first... // Why will an error occur when this program runs? +// the veriable decimalNumber has already been declared + + // =============> write your prediction here // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { +/*function convertToPercentage(decimalNumber) { const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(decimalNumber); +console.log(decimalNumber);*/ // =============> write your explanation here + // Finally, correct the code to fix the problem // =============> write your new code here +function convertToPercentage(decimalNumber) { + decimalNumber = 0.5; + const percentage = `${decimalNumber * 100}%`; + return percentage; + } \ No newline at end of file diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..0b173735d 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -2,19 +2,29 @@ // Predict and explain first BEFORE you run any code... // this function should square any number but instead we're going to get an error - +// there is nothing con nectimng the 3 to the variable num // =============> write your prediction of the error here -function square(3) { +/*function square(3) { return num * num; } - +*/ // =============> write the error message here +//function square(3) { + // ^ + +//SyntaxError: Unexpected number // =============> explain this error message here +// it was expecting a variable not a number // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + num = 3; + return num * num; +} +console.log(square()); From d0d959c5fabdef2b86074f70dd7d3efaa4445563 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 10 Feb 2026 17:36:45 +0000 Subject: [PATCH 3/4] first 2 sets of tasks done --- Sprint-2/2-mandatory-debug/0.js | 2 +- Sprint-2/2-mandatory-debug/1.js | 11 ++++++++--- Sprint-2/2-mandatory-debug/2.js | 20 ++++++++++++++++---- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..61035773a 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,6 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here it should print "The result of multiplying 10 and 32 is 320" function multiply(a, b) { console.log(a * b); diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..20963ee62 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,18 @@ // Predict and explain first... // =============> write your prediction here - -function sum(a, b) { +//i dont think it will give an answer becuse the semi-colon is after return +/*function sum(a, b) { return; a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); - +*/ // =============> write your explanation here // Finally, correct the code to fix the problem // =============> write your new code here +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/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..f15c204b9 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,9 +1,9 @@ // Predict and explain first... - +// // Predict the output of the following code: -// =============> Write your prediction here +// =============> Write your prediction here i thing this one will work -const num = 103; +/*const num = 103; function getLastDigit() { return num.toString().slice(-1); @@ -11,14 +11,26 @@ function getLastDigit() { console.log(`The last digit of 42 is ${getLastDigit(42)}`); console.log(`The last digit of 105 is ${getLastDigit(105)}`); -console.log(`The last digit of 806 is ${getLastDigit(806)}`); +console.log(`The last digit of 806 is ${getLastDigit(806)}`);*/ // Now run the code and compare the output to your prediction // =============> write the output here +// i was incorrect the const at the top makes them all come out as 3 // Explain why the output is the way it is // =============> write your explanation here +// the constant can't be changed by the code block and num needs to be part of the function // Finally, correct the code to fix the problem // =============> write your new code here +let num = 0; +function getLastDigit(num) { + return num.toString().slice(-1); +} + +console.log(`The last digit of 42 is ${getLastDigit(42)}`); +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 From 795eeb51172c989265e3a79a4b60cdd97aa3b789 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 12 Feb 2026 17:52:22 +0000 Subject: [PATCH 4/4] sprint 2 --- Sprint-2/1-key-errors/0.js | 16 ++------ Sprint-2/1-key-errors/1.js | 13 +----- Sprint-2/1-key-errors/2.js | 16 ++------ Sprint-2/2-mandatory-debug/0.js | 2 +- Sprint-2/2-mandatory-debug/1.js | 11 ++--- Sprint-2/2-mandatory-debug/2.js | 20 ++------- Sprint-2/3-mandatory-implement/1-bmi.js | 7 +++- Sprint-2/3-mandatory-implement/2-cases.js | 7 ++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 11 +++++ Sprint-2/4-mandatory-interpret/time-format.js | 34 --------------- Sprint-2/5-stretch-extend/format-time.js | 25 ----------- Sprint-2/readme.md | 41 ------------------- 12 files changed, 39 insertions(+), 164 deletions(-) delete mode 100644 Sprint-2/4-mandatory-interpret/time-format.js delete mode 100644 Sprint-2/5-stretch-extend/format-time.js delete mode 100644 Sprint-2/readme.md diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index b9e0d1397..653d6f5a0 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,23 +1,13 @@ // Predict and explain first... // =============> write your prediction here -// you will get an error becuase srt has alredy been declared - // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring -/*function capitalise(str) { +function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str;*/ - + return str; +} // =============> write your explanation here -//let str = `${str[0].toUpperCase()}${str.slice(1)}`; - // ^ - -//SyntaxError: Identifier 'str' has already been declared // =============> write your new code here -function capitalise(str) { - let strTwo = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; -} \ No newline at end of file diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index d631960ac..f2d56151f 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,29 +1,20 @@ // Predict and explain first... // Why will an error occur when this program runs? -// the veriable decimalNumber has already been declared - - // =============> write your prediction here // Try playing computer with the example to work out what is going on -/*function convertToPercentage(decimalNumber) { +function convertToPercentage(decimalNumber) { const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(decimalNumber);*/ +console.log(decimalNumber); // =============> write your explanation here - // Finally, correct the code to fix the problem // =============> write your new code here -function convertToPercentage(decimalNumber) { - decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; - return percentage; - } \ No newline at end of file diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index 0b173735d..aad57f7cf 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -2,29 +2,19 @@ // Predict and explain first BEFORE you run any code... // this function should square any number but instead we're going to get an error -// there is nothing con nectimng the 3 to the variable num + // =============> write your prediction of the error here -/*function square(3) { +function square(3) { return num * num; } -*/ -// =============> write the error message here -//function square(3) { - // ^ -//SyntaxError: Unexpected number +// =============> write the error message here // =============> explain this error message here -// it was expecting a variable not a number // Finally, correct the code to fix the problem // =============> write your new code here -function square(num) { - num = 3; - return num * num; -} -console.log(square()); diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index 61035773a..b27511b41 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,6 @@ // Predict and explain first... -// =============> write your prediction here it should print "The result of multiplying 10 and 32 is 320" +// =============> write your prediction here function multiply(a, b) { console.log(a * b); diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 20963ee62..37cedfbcf 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,18 +1,13 @@ // Predict and explain first... // =============> write your prediction here -//i dont think it will give an answer becuse the semi-colon is after return -/*function sum(a, b) { + +function sum(a, b) { return; a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -*/ + // =============> write your explanation here // Finally, correct the code to fix the problem // =============> write your new code here -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/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index f15c204b9..57d3f5dc3 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,9 +1,9 @@ // Predict and explain first... -// + // Predict the output of the following code: -// =============> Write your prediction here i thing this one will work +// =============> Write your prediction here -/*const num = 103; +const num = 103; function getLastDigit() { return num.toString().slice(-1); @@ -11,26 +11,14 @@ function getLastDigit() { console.log(`The last digit of 42 is ${getLastDigit(42)}`); console.log(`The last digit of 105 is ${getLastDigit(105)}`); -console.log(`The last digit of 806 is ${getLastDigit(806)}`);*/ +console.log(`The last digit of 806 is ${getLastDigit(806)}`); // Now run the code and compare the output to your prediction // =============> write the output here -// i was incorrect the const at the top makes them all come out as 3 // Explain why the output is the way it is // =============> write your explanation here -// the constant can't be changed by the code block and num needs to be part of the function // Finally, correct the code to fix the problem // =============> write your new code here -let num = 0; -function getLastDigit(num) { - return num.toString().slice(-1); -} - -console.log(`The last digit of 42 is ${getLastDigit(42)}`); -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 diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..e3ce6759c 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,8 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height -} \ No newline at end of file + let heightsq = height * height; + return weight/heightsq; + // return the BMI of someone based off their weight and height +} +console.log(calculateBMI(30, 10)); \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..4a62e10a5 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,10 @@ // You will need to come up with an appropriate name for the function // Use the MDN string documentation to help you find a solution // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase + +function SNAKE_CASE (mesasge){ + let snake = mesasge.replace(/ /g,"_"); + let upper = snake.toUpperCase(); + return upper; +} +console.log(SNAKE_CASE("hello there")); \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..fc5dbfb36 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,14 @@ // 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(penceString) { + let penceStringWithoutTrailingP = penceString.replace( /[^1-9]/g, ""); //39772 + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); //39772 + const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); // 397 + const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2) +.padEnd(2, "0"); // 72 + return `£${pounds}.${pence}`; // 397.72 + +} +console.log(toPounds("397d72p")); diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js deleted file mode 100644 index 7c98eb0e8..000000000 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ /dev/null @@ -1,34 +0,0 @@ -function pad(num) { - return num.toString().padStart(2, "0"); -} - -function formatTimeDisplay(seconds) { - const remainingSeconds = seconds % 60; - const totalMinutes = (seconds - remainingSeconds) / 60; - const remainingMinutes = totalMinutes % 60; - const totalHours = (totalMinutes - remainingMinutes) / 60; - - return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; -} - -// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit -// to help you answer these questions - -// Questions - -// a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here - -// 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? -// =============> write your answer here - -// c) What is the return value of pad is called for the first time? -// =============> write your answer here - -// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here - -// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js deleted file mode 100644 index 32a32e66b..000000000 --- a/Sprint-2/5-stretch-extend/format-time.js +++ /dev/null @@ -1,25 +0,0 @@ -// This is the latest solution to the problem from the prep. -// Make sure to do the prep before you do the coursework -// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. - -function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; - } - return `${time} am`; -} - -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; -console.assert( - currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` -); - -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; -console.assert( - currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` -); diff --git a/Sprint-2/readme.md b/Sprint-2/readme.md deleted file mode 100644 index 44c118e33..000000000 --- a/Sprint-2/readme.md +++ /dev/null @@ -1,41 +0,0 @@ -# 🧭 Guide to week 2 exercises - -> https://programming.codeyourfuture.io/structuring-data/sprints/2/prep/ - -> [!TIP] -> You should always do the prep work _before_ attempting the coursework. -> The prep shows you how to do the coursework. -> There is often a step by step video you can code along with too. -> Do the prep. - -## 1 Errors - -In this section, you need to go to each file in `errors` directory. Read the file and predict what error will happen. Then run the file with node to check what the error is. Your task is to interpret the error message and explain why it occurs. The [errors documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors) will help you figure out the solution. - -## 2 Debug - -In this section, you need to go to each file in `debug` to **explain and predict** why the program isn't behaving as intended. Then you'll need to run the program with node to check your prediction. You will also need to correct the code too. - -## 3 Implement - -In this section, you will have a short set of requirements about a function. You will need to implement a function based off this set of requirements. Make sure you check your function works for a number of different inputs. - -Here is a recommended order: - -1. `1-bmi.js` -1. `2-cases.js` -1. `3-to-pounds.js` - -## 4 Interpret - -In these tasks, you have to interpret a slightly larger program with some syntax / operators / functions that may be unfamiliar. - -You must use documentation to make sense of anything unfamiliar. Learning how to look things up this way is a fundamental part of being a developer! - -You can also use `console.log` to check the value of different variables in the code. - -## 5 Extend - -In the prep for this sprint, we developed a function to convert 24 hour clock times to 12 hour clock times. - -Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. This section is not mandatory, but it will also help you solve some similar kata in Codewars.