Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
576dc5a
Predicted what I expect, explained Syntax Error, added the new code
Sep 24, 2026
342efc6
deleted old code in 0.js
Sep 24, 2026
f47f36b
1.js result predicted, explained the errors, and wrote new code
Sep 24, 2026
41e9a7a
1.js old code deleted
Sep 24, 2026
9c61083
2.js SyntaxError expected, explained the error, wrote new code, delet…
Sep 24, 2026
3ecd296
grammar correction
Sep 25, 2026
55f005d
2-mandatory-debug 0.jsedited, expectation stated, code fixed
AlanGit-debug2604 Sep 26, 2026
bc68642
2-manadatory-debug 0.js edited, expectation stated
AlanGit-debug2604 Sep 26, 2026
a243d6d
2-mandatory-debug 1.jsedited, expectation stated, code fixed
AlanGit-debug2604 Sep 26, 2026
1b09621
2-mandatory-debug 0.js added Undefined in expectation.
Sep 27, 2026
742ac3f
2-mandatory-debug 2.js edited, result predicted, prediction compared,…
Sep 27, 2026
9ba67d2
3-mandatory-implement 1-bmi.js Implemented BMI calculation function a…
Sep 27, 2026
6be655b
Fix typo in comment explaining undefined behavior in multiply function
Sep 27, 2026
cf2bf33
3-mandatory-implement 2-cases.js Implemented upperSnakeCase function …
Sep 27, 2026
9a86ff0
3-mandatory-implement 3-to-pounds.js Implement toPound function to co…
Sep 28, 2026
0142183
3-to-pound.js : Refactor parameter name (wholePenceStringWithP) in to…
Sep 28, 2026
c4affdd
formatTime.js formatAs12HourClock function to correctly handle hour i…
Sep 28, 2026
d35a846
Remove Prep folder files from PR
Sep 28, 2026
214b717
Removed empty files
Sep 28, 2026
8e32548
Remove Prep files from PR
Sep 28, 2026
1d3a340
3-to-pound.js: added test cases
Sep 28, 2026
b8dc470
use by Method .toFixed(1) to return BMI in string in one decimal place
Sep 29, 2026
773c6bc
format-time.js edited to run `const` minutes =time.slice(-2); and fi…
Sep 29, 2026
01c7b46
Fix time formatting for hours >= 24 and ensure leading zeros for sing…
Sep 29, 2026
fe78cd5
Refactor time formatting logic to correctly handle hours between 12 a…
Sep 29, 2026
fa9defb
Fix time formatting to handle hours >= 24 and adjust AM/PM representa…
Oct 1, 2026
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
9 changes: 4 additions & 5 deletions Sprint-3/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Predict and explain first...
// =============> write your prediction here
// =============> I expect the function capitalise will turn first letter of string given by user into capital letter.

// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring

// =============> The result was a Syntax error because str has been declared as parameter of function captialise before let reassign str.
// =============>
function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
Comment thread
cjyuan marked this conversation as resolved.
}

// =============> write your explanation here
// =============> write your new code here
15 changes: 6 additions & 9 deletions Sprint-3/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
// =============> SyntaxError will occurs

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

// =============> decimalNumber first declared as parameter, it cannot be reassigned as const.
// Also, console.log try to run decimalNumber as a variable while decimalNumber was assigned as a parameter.
// Finally, correct the code to fix the problem
// =============> write your new code here
function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;

return percentage;
}

console.log(decimalNumber);

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

// Finally, correct the code to fix the problem
// =============> write your new code here
console.log(convertToPercentage(0.5));
17 changes: 7 additions & 10 deletions Sprint-3/1-key-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@

// Predict and explain first BEFORE you run any code...

// this function should square any number but instead we're going to get an error

// =============> write your prediction of the error here

function square(3) {
return num * num;
}
// =============> I expect SyntaxError will result

// =============> write the error message here
// =============> SyntaxError: Unexpected number

// =============> explain this error message here
// =============> Numerical character "3" cannot be named as parameter of a function.

// Finally, correct the code to fix the problem

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


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

// =============> write your prediction here
// =============> Undefined at the end of sentence. console.log in local function will result the product. But console.log in global scope will not call function multiply.

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

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

// =============> write your explanation here
//console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

// =============> The function multiply does not really carry out the multiplication. It only logs the result of a*b. That's why calling multiply become undefined.
// 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)}`);
19 changes: 12 additions & 7 deletions Sprint-3/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// Predict and explain first...
// =============> write your prediction here
// =============> I predict a SyntaxError in original code

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
// =============> Expression a + b is not assigned to 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)}`);
30 changes: 21 additions & 9 deletions Sprint-3/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here
// =============> Code returns last digit of 103 which is the value of num assigned in global scope.

//const num = 103;

//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)}`);

// Now run the code and compare the output to your prediction
// =============>
// 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
// =============> The function refers to the value of `num` assigned in global scope rather than getLastDigit, because 'num' was not a parameter in function name.
// Finally, correct the code to fix the problem
// =============>
const num = 103;

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

// Now run the code and compare the output to your prediction
// =============> write the output here
// Explain why the output is the way it is
// =============> write your explanation here
// Finally, correct the code to fix the problem
// =============> write your new code here

// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
13 changes: 13 additions & 0 deletions Sprint-3/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,17 @@

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
return (weight / Math.pow(height, 2)).toFixed(1);
}

console.log(
`BMI base off weight in kg and height in metres is ${calculateBMI(70, 1.73)}`,
);

//draft pseudocode below
//name of function calculateBMI
//key word return
//parameters : weight, height
//formula weight / height x height
//or weight / sqr height (by Method: Math.pow(parameter,power))
//by Method .toFixed(1) to return BMI in string in one decimal place
11 changes: 11 additions & 0 deletions Sprint-3/3-mandatory-implement/2-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@
// 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

//pseudocode draft below
//Name of function upperSnakeCase
//Parameter (userInputString) type: String
//Method .toUpperCase() .replaceAll("","_")
//print by console.log (`${userInputString()`})

function upperSnakeCase(userInputString) {
return userInputString.toUpperCase().replaceAll(" ", "_");
}
console.log(upperSnakeCase("hello world"));
32 changes: 32 additions & 0 deletions Sprint-3/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,35 @@
// 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 name toPound
//identifier of prev code :
// 1 penceString - user input ; Type: String, count length by .length
// 2 penceStringWithoutTrailingP ; cut the tail p by .substring ()
// 3 paddedPenceNumberString ; assign and prescribe target length of pence in three characters length by .padStart()
// 4 pounds ; assign pounds from first character of paddedPenceNumberString, cut the last two character by .substring
// 5 pence ; assign pence starting from last two character of paddedPenceNumberString
// Parameter to name wholePenceStringWithP

function toPound(wholePenceStringWithP) {
const penceStringWithoutTrailingP = wholePenceStringWithP.substring(
0,
wholePenceStringWithP.length - 1,
);

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2,
);

const pence = paddedPenceNumberString.substring(
paddedPenceNumberString.length - 2,
);

return `£${pounds}.${pence}`;
}
console.log(toPound("399p"));
console.log(toPound("1399p"));
console.log(toPound("99p"));
console.log(toPound("9p"));
13 changes: 7 additions & 6 deletions Sprint-3/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@ function formatTimeDisplay(seconds) {
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
}

console.log(formatTimeDisplay(61));

// 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
// =============> 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?
// =============> write your answer here
// =============> 0

// c) What is the return value of pad when it 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. The last pad call takes `remainingSeconds` as its argument, and 61 % 60 =1 , so num is 1.
// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
// =============> write your answer here
// =============> 01. `numString` starts as "1", which has one character length. Since 1 < 1, the while lines run and pad "0", giving "01". Now this new `numString` has two characters length, so the while loop stops and returns "01".
48 changes: 41 additions & 7 deletions Sprint-3/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,56 @@

function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
if (hours > 12) {
return `${hours - 12}:00 pm`;
const minutes = time.slice(-2);
if (hours > 22) {
return `${hours - 12}:${minutes} pm`;
} else if (hours > 12) {
return `0${hours - 12}:${minutes} pm`;
} else if (hours > 9) {
return `${hours}:${minutes} am`;
} else if (hours < 1) {
return `12:${minutes} am`;
}
return `${time} am`;

return `0${hours}:${minutes} am`;
}

const currentOutput = formatAs12HourClock("08:00");
const targetOutput = "08:00 am";
const currentOutput = formatAs12HourClock("08:01");
const targetOutput = "08:01 am";
console.assert(
currentOutput === targetOutput,
`current output: ${currentOutput}, target output: ${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}`
`current output: ${currentOutput2}, target output: ${targetOutput2}`,
);

const currentOutput3 = formatAs12HourClock("00:01");
const targetOutput3 = "12:01 am";
console.assert(
currentOutput3 === targetOutput3,
`current output: ${currentOutput3}, target output: ${targetOutput3}`,
);

const currentOutput4 = formatAs12HourClock("11:01");
const targetOutput4 = "11:01 am";
console.assert(
currentOutput4 === targetOutput4,
`current output: ${currentOutput4}, target output: ${targetOutput4}`,
);

console.log(formatAs12HourClock("08:01"));
console.log(formatAs12HourClock("23:55"));
console.log(formatAs12HourClock("00:01"));
console.log(formatAs12HourClock("11:01"));
console;

//Two patches
//First hour input > 24, current algo is hours - 12 , e.g. 25-12 and print 13:00pm , rather than 1:00am (+1)
//to Define `hoursOfOneDay` = 24
//2 min input
//to Define