Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c85f975
complete ex 0.js
fatimarouchi Sep 30, 2026
e071e69
complete ex 1.js
fatimarouchi Sep 30, 2026
6570ced
write prediction for 2.js
fatimarouchi Sep 30, 2026
001939b
complete ex 2.js
fatimarouchi Sep 30, 2026
9650964
complete ex 0.js
fatimarouchi Sep 30, 2026
af75a19
complete ex 1.js
fatimarouchi Sep 30, 2026
12f14c1
complete ex 2.js
fatimarouchi Sep 30, 2026
cdac639
complete ex 1-bmi.js
fatimarouchi Sep 30, 2026
4089ba3
complete ex. 2-cases.js
fatimarouchi Sep 30, 2026
acc0e01
complete ex 3-to-pounds.js
fatimarouchi Sep 30, 2026
f80713c
complete ex time-format.js
fatimarouchi Sep 30, 2026
86827f4
complete ex format-time.js
fatimarouchi Sep 30, 2026
9f55f62
Fix 12-hour clock conversion and add edge-case tests
fatimarouchi Sep 30, 2026
c566c35
Fix time conversion
fatimarouchi Sep 30, 2026
ebea776
Pad single-digit minutes in time formatter
fatimarouchi Oct 2, 2026
d6fd51e
Handle empty strings in capitalise function
fatimarouchi Oct 2, 2026
dc6b184
Format percentage output to one decimal place
fatimarouchi Oct 2, 2026
60c1518
Handle multiple spaces in case conversion
fatimarouchi Oct 2, 2026
8ee83a9
Support pence values with or without the p suffix
fatimarouchi Oct 2, 2026
7a70e63
Fix 12-hour time formatting for leading-zero hours
fatimarouchi Oct 6, 2026
f7dd186
Fix 12-hour time formatting and tests
fatimarouchi Oct 6, 2026
6270b24
Add UPPER_SNAKE_CASE test cases
fatimarouchi Oct 6, 2026
53bf711
Add BMI checks for multiple inputs
fatimarouchi Oct 6, 2026
1d34e47
Fix percentage formatting
fatimarouchi Oct 6, 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
20 changes: 16 additions & 4 deletions Sprint-3/1-key-errors/0.js
Comment thread
fatimarouchi marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
// Predict and explain first...
// =============> write your prediction here
// =============>// I predict JavaScript will give a SyntaxError because str is declared twice in the function.

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

// =============> write your explanation here
capitalise("hello");*/
/* =============> The error happens because str is already the function's parameter.
let str tries to use the same name again, so JavaScript gives a SyntaxError.
The function stops before it can run. */
// =============> write your new code here
function capitalise(str) {
if (str === "") {
return "";
}

const result = `${str[0].toUpperCase()}${str.slice(1)}`;
return result;
}

console.log(`Result: "${capitalise("")}"`);
17 changes: 13 additions & 4 deletions Sprint-3/1-key-errors/1.js
Comment thread
fatimarouchi marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
// =============>// I predict a SyntaxError because decimalNumber is declared as a parameter and then declared again with const.

// 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
/* =============> decimalNumber is already the function parameter.
const decimalNumber tries to declare the same name again inside the function,
so JavaScript gives a SyntaxError. */

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

return percentage;
}

console.log(convertToPercentage(0.5));
Comment thread
fatimarouchi marked this conversation as resolved.
17 changes: 9 additions & 8 deletions Sprint-3/1-key-errors/2.js
Comment thread
fatimarouchi marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@

// 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
// =============> // I predict a SyntaxError because 3 is a number, but a function parameter needs to be a name.

function square(3) {
/*function square(3) {
return num * num;
}
*/
// =============> SyntaxError: Unexpected number

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

// =============> explain this error message here
// =============> The error happens because 3 is not a name. A parameter needs a name, like num.

// Finally, correct the code to fix the problem

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


function square(num) {
return num * num;
}
console.log(square(3));
14 changes: 9 additions & 5 deletions Sprint-3/2-mandatory-debug/0.js
Comment thread
fatimarouchi marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// Predict and explain first...

// =============> write your prediction here
// =============> I couldn't predict until I run the code

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

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

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

/* =============> The Terminal gives an answer of 320 but also says "The result of multiplying 10 and 32 is undefined"
which makes me think that the function has no return so it gives back 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)}`);
14 changes: 10 additions & 4 deletions Sprint-3/2-mandatory-debug/1.js
Comment thread
fatimarouchi marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// Predict and explain first...
// =============> write your prediction here
// =============> I predict the code won't work because there's a ";" 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)}`);
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);*/

// =============> write your explanation here
/* =============> The sum is undefined because the semicolon after return ends it too early,
the function returns before adding a and b.*/
// 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)}`);
29 changes: 24 additions & 5 deletions Sprint-3/2-mandatory-debug/2.js
Comment thread
fatimarouchi marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here
// =============> I predict the result will be wrong because the num is set set on 103.

const num = 103;
/*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)}`);
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 output:
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
/* =============> The problem is that the function ignores the numbers passed to it,
it always uses num, which is 103, so it returns 3 every time.*/
// Finally, correct the code to fix the problem
// =============> write your new code here
/*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)}`);*/
// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
// In this case getLastDigit is not working because it's parameter is empty and not declared.
// Here's the right code:
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)}`);
17 changes: 16 additions & 1 deletion Sprint-3/3-mandatory-implement/1-bmi.js
Comment thread
fatimarouchi marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,20 @@
// It should return a string of their Body Mass Index to 1 decimal place

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

console.log(calculateBMI(52, 1.63));
Comment thread
fatimarouchi marked this conversation as resolved.

console.assert(
calculateBMI(70, 1.73) === "23.4",
"Expected BMI for 70kg and 1.73m to be 23.4",
);
console.assert(
calculateBMI(80, 1.8) === "24.7",
"Expected BMI for 80kg and 1.8m to be 24.7",
);
console.assert(
calculateBMI(60, 1.6) === "23.4",
"Expected BMI for 60kg and 1.6m to be 23.4",
);
14 changes: 14 additions & 0 deletions Sprint-3/3-mandatory-implement/2-cases.js
Comment thread
fatimarouchi marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@
// 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(words) {
return words.toUpperCase().trim().split(/\s+/).join("_");
}

console.log(toUpperSnakeCase("hello there"));
Comment thread
fatimarouchi marked this conversation as resolved.

console.assert(
toUpperSnakeCase("hello") === "HELLO",
'Expected "hello" to become "HELLO"',
);
console.assert(
toUpperSnakeCase(" hello there ") === "HELLO_THERE",
"Expected extra spaces to be trimmed and collapsed to one underscore",
);
17 changes: 17 additions & 0 deletions Sprint-3/3-mandatory-implement/3-to-pounds.js
Comment thread
fatimarouchi marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,20 @@
// 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 penceNumberString = String(penceString).replace(/p$/i, "");
const paddedPenceNumberString = penceNumberString.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("599p"));
console.log(toPounds("6p"));
console.log(toPounds("2568p"));
12 changes: 6 additions & 6 deletions Sprint-3/4-mandatory-interpret/time-format.js
Comment thread
fatimarouchi marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,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
// =============>Pad will be called 3 times: once for hours, once for minutes, and once for seconds.

// 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
// =============> the first time pad is called, num gets the value of totalHours, which is 0.

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

// =============> the first time pad is called, it returns 00 because num is 0 and pad adds a zero in front.
// 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
// =============> the last time pad is called, num is 1 because there is 1 second left.

// 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
// =============>the last time pad is called, it returns 01 because num is 1 and pad adds a 0 in front.
46 changes: 29 additions & 17 deletions Sprint-3/5-stretch-extend/format-time.js
Comment thread
fatimarouchi marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,35 @@
// 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`;
const [hoursString, minutesString = "00"] = time.split(":");
const hours = Number(hoursString);
const minutes = minutesString.padStart(2, "0");

let suffix = "am";
if (hours >= 12) {
suffix = "pm";
}
return `${time} am`;

const formattedHours = String(hours % 12 || 12).padStart(2, "0");

return `${formattedHours}:${minutes} ${suffix}`;
}
Comment thread
fatimarouchi marked this conversation as resolved.

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}`
);
function check(input, expected) {
const actual = formatAs12HourClock(input);

if (actual !== expected) {
console.error(`FAIL: ${input} -> ${actual} (expected ${expected})`);
process.exitCode = 1;
}
}

check("23:00", "11:00 pm");
check("12:00", "12:00 pm");
check("00:00", "12:00 am");
check("08:00", "08:00 am");
check("9:5", "09:05 am");

if (!process.exitCode) {
console.log("All formatAs12HourClock tests passed.");
}
Loading