Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ function capitalise(str) {

// =============> write your explanation here
// =============> write your new code here
// [ChunYanWong]The uncaught type error will occur if the string is empty
// if (str.length > 0) {
// let str = ...
//
4 changes: 4 additions & 0 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ function convertToPercentage(decimalNumber) {
console.log(decimalNumber);

// =============> write your explanation here
// [ChunYanWong] decimalNumber is undefined in the main function so error will occur


// Finally, correct the code to fix the problem
// =============> write your new code here
// [ChunYanWong] Add const decimalNumber = 0.5 in the main function

7 changes: 7 additions & 0 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ function square(3) {

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

// [ChunYanWong] Uncaught SyntaxError SyntaxError: Unexpected number

// =============> explain this error message here

// [ChunYanWong] number 3 cannot be parameter

// Finally, correct the code to fix the problem

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

// [ChunYanWong] function square(num) {
// ...


8 changes: 8 additions & 0 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ function multiply(a, b) {

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

// [ChunYanWong]
//320
//The result of multiplying 10 and 32 is undefined

// =============> write your explanation here
// [ChunYanWong] The program can be executed but no return statement in the function and hence no value is returned.

// Finally, correct the code to fix the problem
// =============> write your new code here
// [ChunYanWong]
// console.log(a * b);
// return (a * b)
6 changes: 6 additions & 0 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ function sum(a, b) {

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

// [ChunYanWong]
// The sum of 10 and 32 is undefined

// =============> write your explanation here
// [ChunYanWong] a+b should be included in the return statement

// Finally, correct the code to fix the problem
// =============> write your new code here
// [ChunYanWong] return (a+b);
18 changes: 18 additions & 0 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,30 @@ 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)}`);

// [ChunYanWong] No parameter included in the function and hence the same output

// Now run the code and compare the output to your prediction
// =============> write the output here

// [ChunYanWong]
//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

// [ChunYanWong] No parameter included in the function

// Finally, correct the code to fix the problem
// =============> write your new code here
// [ChunYanWong] function getLastDigit(num) {
// ...

// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
// [ChunYanWong] for the case 12.34, it will return 4 instead of the digit 2
// [ChunYanWong] function getLastDigit(num) {
// return Math.abs(Math.trunc(num)) % 10;
// }

3 changes: 2 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,5 @@

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
return Math.round((weight/(height*height)*10))/10;
}
4 changes: 4 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,7 @@
// 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 toUpperCase(words) {
return words.toUpperCase();
}
20 changes: 20 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,23 @@
// 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}`);

}
6 changes: 5 additions & 1 deletion Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ function formatTimeDisplay(seconds) {

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// [ChunYanWong] 3

// 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
// [ChunYanWong] 0

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// [ChunYanWong] 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
// [ChunYanWong] pad(remainingSeconds) where remainingSeconds = 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
// [ChunYanWong] 01
27 changes: 27 additions & 0 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,30 @@ console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);

// [ChunYanWong] Find the bugs as follows
// Midnight Bug (00:xx): For "00:15", it returns "00:15 am" instead of "12:15 am".
// Noon Bug (12:xx): For "12:35", it hits the else block and returns "12:35 am" instead of "12:35 pm".
// Minutes are Hardcoded: For "16:45", it discards the actual minutes and hardcodes :00 pm, returning "3:00 pm".

//function formatAs12HourClock(time) {
// Guard clause: handle invalid or empty inputs safely
// if (!time || typeof time !== 'string' || !time.includes(':')) {
// return "00:00 am";
// }

// const hours24 = Number(time.slice(0, 2));
// const minutes = time.slice(3, 5); // Preserve actual minutes dynamic input

// Determine am vs pm
// const period = hours24 >= 12 ? "pm" : "am";

// Convert hours to 12-hour format
// let hours12 = hours24 % 12;
// if (hours12 === 0) hours12 = 12; // Adjusts midnight (00) and noon (12) to 12

// Format hours back into a 2-digit padded string
// const paddedHours = String(hours12).padStart(2, "0");

// return `${paddedHours}:${minutes} ${period}`;
//}
Loading