Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2c6aae7
1-key-errors,0.js, completed
Nov 1, 2025
876bf7b
Fix variable shadowing in capitalise function and update console log;…
Nov 1, 2025
058c055
Fix function definition and error explanations in square function exa…
Nov 1, 2025
c8cebbb
Fix multiply function to return value and update
Nov 1, 2025
a5bdca3
Fix sum function to return correct value and update console log
Nov 1, 2025
7ea670b
Fix getLastDigit function to accept parameter and return correct last…
Nov 1, 2025
f5b79bf
Implement BMI calculation function and log result
Nov 1, 2025
b760859
Fix console log statement formatting in BMI calculation
Nov 2, 2025
1f37466
Implement toUpperSnakeCase function to convert strings to UPPER_SNAKE…
Nov 2, 2025
e943a03
Implement toPounds function to convert pence to pounds and log results
Nov 2, 2025
5f29b84
Refactor comments and formatting in time-format.js for clarity
Nov 2, 2025
8ecd330
Refactor formatAs12HourClock function to improve time validation and …
Nov 2, 2025
0e37a64
Update comment to clarify syntax error in capitalise function
Nov 3, 2025
cd942b8
updated the answer on line 4.
Nov 4, 2025
906778c
Remove redundant comments and clarify the capitalise function impleme…
Nov 9, 2025
ed909e1
Fix indentation in commented-out code for clarity in convertToPercent…
Nov 9, 2025
d486397
Update comment to clarify explanation of return statement in sum func…
Nov 9, 2025
6eb8b88
Remove redundant declaration of decimalNumber in convertToPercentage …
Nov 9, 2025
62492e1
Refactor convertToPercentage function to return percentage directly
Nov 9, 2025
25347a2
Fix prediction comment in 2.js to accurately reflect expected output
Nov 9, 2025
ba8d606
Refactor toPounds function for improved readability and consistency
Nov 9, 2025
b185d08
Remove unnecessary comments in formatTimeDisplay function for cleaner…
Nov 9, 2025
c335f18
Delete Sprint-2/2-mandatory-debug/new.js
PaymanIB Nov 10, 2025
696a379
Refactor code structure for improved readability and maintainability
Nov 15, 2025
90a9885
Refactor isProperFraction function to use absolute values for proper …
Nov 15, 2025
a2adf3d
Implement getCardValue function to return numerical values for playin…
Nov 15, 2025
edfe97e
Implement Jest testing framework and coverage reporting
Nov 15, 2025
1d68450
Add additional test cases for isProperFraction function to cover impr…
Nov 15, 2025
4ea61d3
Add tests for getCardValue function to cover number cards, face cards…
Nov 15, 2025
0da6056
reverted to original state
Nov 22, 2025
0ade9b1
reverted to original state
Nov 22, 2025
3f65d2f
Add package-lock.json to .gitignore
Nov 22, 2025
da9c0f7
Remove package-lock.json from version control
Nov 22, 2025
9f2702f
removed sprint 2 from this branch
Nov 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
.DS_Store
.vscode
package-lock.json
**/.DS_Store
17 changes: 11 additions & 6 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// Predict and explain first...
// =============> write your prediction here

// I gives us a syntax error as str declared before.
// 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)}`;
return str;
}
// function capitalise(str) {
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
// return str;
// }

// =============> write your explanation here
// =============> write your explanation here :
// as the variable in side the function has the same name as the function variable.
// =============> write your new code here
function capitalise(str) {
return `${str[0].toUpperCase()}${str.slice(1)}`;
}
console.log(capitalise("abcd"));
30 changes: 20 additions & 10 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// error on line 11
// error on line 17
// Why will an error occur when this program runs? yes
// =============> write your prediction here
// decimalNumber is declared before and can not be declared again.
// console.log(decimalNumber) should be console.log(convertToPercentage)
// Try playing computer with the example to work ot what is going on

// Try playing computer with the example to work out what is going on

function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;
// function convertToPercentage(decimalNumber) {
// const decimalNumber = 0.5;
// const percentage = `${decimalNumber * 100}%`;

return percentage;
}
// return percentage;
// }

console.log(decimalNumber);
//console.log(percentage);

// =============> write your explanation here
// decimalNumber is declared before and can not be declared again.
// console.log(decimalNumber) should be console.log(convertToPercentage)

// Finally, correct the code to fix the problem
// =============> write your new code here
function convertToPercentage(decimalNumber) {
return `${decimalNumber * 100}%`;

}

console.log(convertToPercentage(0.5));
16 changes: 10 additions & 6 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
// this function should square any number but instead we're going to get an error

// =============> write your prediction of the error here
// line 9 num is not defined.

function square(3) {
return num * num;
}
// function square(3) {
// return num * num;
//}

// =============> write the error message here

// SyntaxError: Unexpected number
// =============> explain this error message here

// 3 is not a variable for the function to use. It should be a variable name like num or n.
// Finally, correct the code to fix the problem

// =============> write your new code here


function square(num) {
return num * num;
}
console.log(square(3));
16 changes: 11 additions & 5 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
// Predict and explain first...

// =============> write your prediction here
// it looks fine.

function multiply(a, b) {
console.log(a * b);
}
// function multiply(a, b) {
// console.log(a * b);
//}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

// =============> write your explanation here

// It misses the return value of multiply function.
// Finally, correct the code to fix the problem
// =============> write your new code here
function multiply(a, b) {
return a * b;
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
18 changes: 12 additions & 6 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// Predict and explain first...
// =============> write your prediction here
// there is an error on line 5 and 6
//function sum(a, b) {
// //return;
// a + b;
// }

function sum(a, b) {
return;
a + b;
}

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

// =============> write your explanation here
//the return statement is not returning any value. a+b mentioned after return.
// 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)}`);
28 changes: 20 additions & 8 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,35 @@

// Predict the output of the following code:
// =============> Write your prediction here
// the result will be 3
// const num = 103;

const num = 103;
// function getLastDigit() {
// return num.toString().slice(-1);
// }

function getLastDigit() {
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)}`);
// 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)}`);

// Now run the code and compare the output to your prediction
// =============> write the output here
//The last digit of 42 is 3
// The last digit of 105 is 3
// The last digit of 806 is 3
// Explain why the output is the way it is
// =============> write your explanation here
// because num is defined as 103 and not taking any input from the function parameter.
// Finally, correct the code to fix the problem
// =============> write your new code here

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
// because num is defined as 103 and not taking any input from the function parameter.
5 changes: 4 additions & 1 deletion Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
const bmi = weight / (height * height);
return bmi.toFixed(1);
}
console.log(`The BMI of a person weighing 70kg and 1.73m tall is ${calculateBMI(70, 1.73)}`);
5 changes: 5 additions & 0 deletions Sprint-2/3-mandatory-implement/2-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@
// 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 toUpperSnakeCase(str) {

return str.toUpperCase().replace(/ /g, '_');
}
console.log(toUpperSnakeCase("it's done!"));
22 changes: 22 additions & 0 deletions Sprint-2/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,25 @@
// 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) {
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");

return `£${pounds}.${pence}`;
}
console.log(toPounds("399p"));
console.log(toPounds("50p"));
console.log(toPounds("5p"));
console.log(toPounds("0p"));
console.log(toPounds("12345p"));
10 changes: 7 additions & 3 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@ function formatTimeDisplay(seconds) {
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
// 3 times

// Call formatTimeDisplay with an input of 61, now answer the following:
console.log(formatTimeDisplay(61));

// b) What is the value assigned to num when pad is called for the first time?
// =============> write your answer here

// 0
// c) What is the return value of pad is called for the first time?
// =============> write your answer here

// "00"
// 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

// 1, because remainingSeconds is 1 when pad is called for the last time.
// 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
// "01", because pad adds a leading zero to single digit numbers.
52 changes: 35 additions & 17 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,42 @@
// 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`;

if (!/^\d{2}:\d{2}$/.test(time)) {
return "Invalid time format";
}

const hours = Number(time.slice(0, 2));
const minutes = Number(time.slice(3, 5));
if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59) {
return "Invalid time range";
}
return `${time} am`;
}
let period = "am";
let displayHours = hours;

const currentOutput = formatAs12HourClock("08:00");
const targetOutput = "08:00 am";
console.assert(
currentOutput === targetOutput,
`current output: ${currentOutput}, target output: ${targetOutput}`
);
if (hours === 0) {
displayHours = 12; // midnight
} else if (hours === 12) {
period = "pm"; // noon
} else if (hours > 12) {
displayHours = hours - 12;
period = "pm";
}
const formattedHours = String(displayHours).padStart(2, "0");
const formattedMinutes = String(minutes).padStart(2, "0");
return `${formattedHours}:${formattedMinutes} ${period}`;
}
console.log(formatAs12HourClock("00:00"));

const currentOutput2 = formatAs12HourClock("23:00");
const targetOutput2 = "11:00 pm";
console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);
console.assert(formatAs12HourClock("00:00") === "12:00 am", "Midnight");
console.assert(formatAs12HourClock("12:00") === "12:00 pm", "Noon");
console.assert(formatAs12HourClock("08:30") === "08:30 am", "Morning");
console.assert(formatAs12HourClock("15:45") === "03:45 pm", "Afternoon");
console.assert(formatAs12HourClock("23:59") === "11:59 pm", "Late night");
console.assert(formatAs12HourClock("24:00") === "Invalid time range", "Hour too high");
console.assert(formatAs12HourClock("12:60") === "Invalid time range", "Minute too high");
console.assert(formatAs12HourClock("8:7") === "Invalid time format", "Wrong format");
console.assert(formatAs12HourClock("hello") === "Invalid time format", "Not a time");
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,22 @@ function getAngleType(angle) {
if (angle === 90) {
return "Right angle";
}
// Run the tests, work out what Case 2 is testing, and implement the required code here.
// Then keep going for the other cases, one at a time.

if (angle < 90) {
return "Acute angle";
}

if (angle > 90 && angle < 180) {
return "Obtuse angle";
}

if (angle === 180) {
return "Straight angle";
}

if (angle > 180 && angle < 360) {
return "Reflex angle";
}
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand Down Expand Up @@ -50,14 +64,20 @@ assertEquals(acute, "Acute angle");
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"
const obtuse = getAngleType(120);

// ====> write your test here, and then add a line to pass the test in the function above
assertEquals(obtuse, "Obtuse angle");

// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"
// ====> write your test here, and then add a line to pass the test in the function above
const straight = getAngleType(180);
assertEquals(straight, "Straight angle");

// Case 5: Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"
// ====> write your test here, and then add a line to pass the test in the function above
// ====> write your test here, and then add a line to pass the test in the function above
const reflex = getAngleType(270);
assertEquals(reflex, "Reflex angle");
Loading