Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
26fd354
changed the name of the string in the function
asaniDev Oct 13, 2025
5ab6322
removed line 10 and passed function to console
asaniDev Oct 13, 2025
0c7cc6f
corrected the error with the function
asaniDev Oct 14, 2025
cc216e1
added a return to the function
asaniDev Oct 14, 2025
90013dc
moved the return command to the line below it
asaniDev Oct 14, 2025
f63f7cf
created a function that returns the bmi
asaniDev Oct 14, 2025
a02b0c5
created a function that converts a given string to snake case
asaniDev Oct 14, 2025
e097316
created a toPounds function to return a pounds and pence notation
asaniDev Oct 16, 2025
742c228
answered all the questions in the exercise
asaniDev Oct 16, 2025
0d5ad45
wrote tests for any edge cases and fixed resulting bugs
asaniDev Oct 17, 2025
2038048
made a function for angle types and added tests for all angles
asaniDev Oct 19, 2025
7daf16b
added tests for most fraction types and conditions for them as well
asaniDev Oct 22, 2025
dfebb97
added conditions for all ranks in a deck of cards and tests for them
asaniDev Oct 22, 2025
6865348
added jest tests for all angle types
asaniDev Oct 22, 2025
43d650c
added jest tests for different card values
asaniDev Oct 22, 2025
3ca95c6
took away comment on line 30
asaniDev Oct 22, 2025
c56bd67
revert multiple commits that were from sprint 2
asaniDev Oct 27, 2025
2765c49
added tests for multiple samples, removed a test for ace of spades, c…
asaniDev Oct 29, 2025
035e27e
removed check for ace of spades, adjusted rank to give the full value…
asaniDev Oct 29, 2025
50ee9ef
corrected test for numerator is 0 to a proper fraction, and removed u…
asaniDev Nov 17, 2025
bcbd867
added a regex to make sure only exact number card value matches will …
asaniDev Nov 17, 2025
137fd7c
added a few tests for negative improper fractions
asaniDev Nov 17, 2025
e5b18e4
added more tests to make the test suites more robust, moved ten to nu…
asaniDev Nov 17, 2025
5fa3d08
removed console.log used for testing.
asaniDev Nov 17, 2025
d58910a
used regex pattern to check for ranks and removed includes method
asaniDev Nov 20, 2025
8b52886
added dev dependencies
asaniDev Nov 20, 2025
78f21df
revert changes to sprint 2 folder
asaniDev Nov 22, 2025
8ad9d08
reverted changes to 1.js
asaniDev Nov 22, 2025
14ddfad
reverted changes to 2.js in sprint 2 file.
asaniDev Nov 22, 2025
1a5aada
revert unwanted change
asaniDev 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
15 changes: 4 additions & 11 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
// Predict and explain first...

// =============> write your prediction here
//line 7 will log the result of a * b, line 10 will throw an error since the function does not return anything so it will say The result of multiplying 10 and 32 is undefined.

//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
//since the function does not return a value we get undefined passed back to the console.

// 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)}`);
17 changes: 5 additions & 12 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
// Predict and explain first...
// =============> write your prediction here
// the console will show The sum of 10 and 32 is undefined, this is because the return command is before the calculation so the return has no value to bring back.

//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 console will show The sum of 10 and 32 is undefined, this is because the return command is before the calculation so the return has no value to bring back.
// 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)}`);
13 changes: 2 additions & 11 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,5 @@
// 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
const bmi = weight / height ** 2;
return bmi.toFixed(1);
}

console.log(`Your BMI is ${calculateBMI(70, 1.73)}`);

//const actualOutput = calculateBMI(70, 1.73);
//const targetOutput = "23.4";

//console.assert(actualOutput === targetOutput, `That is not the correct BMI`);
// return the BMI of someone based off their weight and height
}
6 changes: 0 additions & 6 deletions Sprint-2/3-mandatory-implement/2-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,3 @@
// 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 convertToSnakeCase(inputStr) {
const newStr = inputStr.toUpperCase().replaceAll(" ", "_");
return newStr;
}

console.log(convertToSnakeCase("hello there"));
45 changes: 0 additions & 45 deletions Sprint-2/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,3 @@
// 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"));

const actualOutput = toPounds("4685p");
const expectedOutput = "£46.85";

console.assert(
actualOutput === expectedOutput,
`expected to get ${expectedOutput}, but got ${actualOutput}`
);

const actualOutput1 = toPounds("123456p");
const expectedOutput1 = "£1234.56";

console.assert(
actualOutput1 === expectedOutput1,
`expected to get ${expectedOutput1}, but got ${actualOutput1}`
);

const actualOutput2 = toPounds("4p");
const expectedOutput2 = "£0.04";

console.assert(
actualOutput2 === expectedOutput2,
`expected to get ${expectedOutput2}, but got ${actualOutput2}`
);
12 changes: 5 additions & 7 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,24 @@ 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 it will be called 3 times
// =============> 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 num = 0 on the first call
// =============> write your answer here

// c) What is the return value of pad is called for the first time?
// =============> write your answer here return value = "00"
// =============> 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 num = 1 when called for the last time because remainingSeconds has a value of 1 from 61%60 = 1
// =============> 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 return value will be "01" since num has 1 digit pad adds a 0 to the start to make it 2 digits.
// =============> write your answer here
22 changes: 1 addition & 21 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@

function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
const minutes = time.slice(3);
console.log(minutes);
if (hours == 12) {
return `${hours}:${minutes} pm`;
}

if (hours > 12) {
return `${hours - 12}:${minutes} pm`;
return `${hours - 12}:00 pm`;
}
return `${time} am`;
}
Expand All @@ -29,17 +23,3 @@ console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);

const currentOutput3 = formatAs12HourClock("23:30");
const targetOutput3 = "11:30 pm";
console.assert(
currentOutput3 === targetOutput3,
`current output: ${currentOutput3}, target output: ${targetOutput3}`
);

const currentOutput4 = formatAs12HourClock("12:01");
const targetOutput4 = "12:01 pm";
console.assert(
currentOutput4 === targetOutput4,
`current output: ${currentOutput4}, target output: ${targetOutput4}`
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
if (Math.sign(numerator) === -1 || Math.sign(denominator) === -1) {
if (Math.abs(numerator) < Math.abs(denominator)) {
return true;
}
} else if (numerator === 0) {
return false;
}

if (numerator < denominator) {
if (Math.abs(numerator) < Math.abs(denominator)) {
return true;
} else if (numerator > denominator) {
return false;
} else if (numerator === denominator) {
return false;
} else if (numerator === 0) {
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
// write one test at a time, and make it pass, build your solution up methodically
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
function getCardValue(card) {
const rank = card[0];
let rank = "";

if (card === "A♠") {
return 11;
} else if (Number(rank) > 1 && Number(rank) < 10) {
for (let i = 0; i < card.length - 1; i++) {
rank += card[i];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach work.

You could also consider using built-in functions (methods) of String. Mastering these String's methods can simplify a lot of string processing tasks.


if (Number.isInteger(Number(rank)) && Number(rank) > 1 && Number(rank) < 10) {
return Number(rank);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In JavaScript, strings that represent valid numeric literals in the language can be safely
converted to equivalent numbers or parsed into a valid integers.
Do you want to recognize these string values as valid ranks?

To find out what these strings are, you can ask AI

What kinds of string values would make Number(rank) evaluate to 2 in JS?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added a regex to only allow specific numeric literals that convert to numbers which would be in our range 2 -10 and ignore all others.

} else if (rank === "10" || rank === "J" || rank === "Q" || rank === "K") {
return 10;
Expand Down Expand Up @@ -68,5 +70,5 @@ assertEquals(ace, 11);
// Given a card with an invalid rank (neither a number nor a recognized face card),
// When the function is called with such a card,
// Then it should throw an error indicating "Invalid card rank."
const invalidCard = getCardValue("15♠");
const invalidCard = getCardValue("100♠");
assertEquals(invalidCard, "Invalid card rank.");
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ test("should return true for a proper fraction", () => {
// Case 2: Identify Improper Fractions:
test("should return false for an improper fraction", () => {
expect(isProperFraction(7, 4)).toEqual(false);
expect(isProperFraction(35, 8)).toEqual(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also test some negative improper fractions in this test.

});

// Case 3: Identify Negative Fractions:
test("should return true for a proper fraction based on the absolute values of the numerator and denominator", () => {
expect(isProperFraction(-3, 8)).toEqual(true);
expect(isProperFraction(-3, -8)).toEqual(true);
expect(isProperFraction(3, -8)).toEqual(true);
expect(isProperFraction(3, 8)).toEqual(true);
});

// Case 4: Identify Equal Numerator and Denominator:
test("should return false for an equal fraction", () => {
expect(isProperFraction(4, 4)).toEqual(false);
expect(isProperFraction(-7, -7)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@
// We will use the same function, but write tests for it using Jest in this file.
const getCardValue = require("../implement/3-get-card-value");

test("should return 11 for Ace of Spades", () => {
const aceofSpades = getCardValue("A♠");
expect(aceofSpades).toEqual(11);
});

// Case 2: Handle Number Cards (2-10):
test("should return a number matchig the rank value for given card", () => {
test("should return a number matchig the rank value for number cards", () => {
const numberCard = getCardValue("5♠");
expect(numberCard).toEqual(5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could test multiple samples (especially the boundary cases, "2♠" and "10♠") to make the test more robust.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a suite of tests for different values to make the test more robust

});
// Case 3: Handle Face Cards (J, Q, K):
test("should return 10 for Face Cards", () => {
const faceCard = getCardValue("K♠");
const faceCard = getCardValue("10♠");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Face cards are J, Q, K. 10 is consider a number card.

expect(faceCard).toEqual(10);
});
// Case 4: Handle Ace (A):
Expand All @@ -23,7 +18,12 @@ test("should return 11 for Ace", () => {
expect(aceCard).toEqual(11);
});
// Case 5: Handle Invalid Cards:
test("should return 11 for Ace of Spades", () => {
const invalidCard = getCardValue("1♥");
test("should return invalid card rank for cards that are not in the suite", () => {
const invalidCard = getCardValue("100♥");
expect(invalidCard).toEqual("Invalid card rank.");
});

test("should return invalid card rank for cards that are not in the suite", () => {
const invalidCard = getCardValue("3.1416♥");
expect(invalidCard).toEqual("Invalid card rank.");
});
Comment on lines 25 to 31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They both test "invalid case". Consider combine them into one test but using multiple samples.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combined the tests and added more tests for different values