Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
847f273
describe what line 3 is doing
jamesishimwe Mar 8, 2026
549e2b3
assign initials the values returned after each name is passed to subs…
jamesishimwe Mar 8, 2026
780e06a
create variables,dir and ext
jamesishimwe Mar 8, 2026
5a22c35
work out what num represents
jamesishimwe Mar 8, 2026
4beaaa7
use documentation to break down num
jamesishimwe Mar 10, 2026
ab64056
turn the line into comments
jamesishimwe Mar 10, 2026
24827db
declare age using let instead of const
jamesishimwe Mar 10, 2026
df994e9
declare the variable cityOfBirth before using it
jamesishimwe Mar 10, 2026
040dd2c
convert cardNumber into a string before using slice on it
jamesishimwe Mar 10, 2026
f497f02
rename variables and start with a letter
jamesishimwe Mar 10, 2026
28fb9f2
add comma to separate arguments taken by replaceAll
jamesishimwe Mar 10, 2026
d02994a
answer the questions
jamesishimwe Mar 10, 2026
51078bc
answer the questions
jamesishimwe Mar 10, 2026
7bcd0d3
answer the questions
jamesishimwe Mar 10, 2026
2751726
answer the questions
jamesishimwe Mar 10, 2026
8f083a5
answer the questions
jamesishimwe Mar 10, 2026
3b63357
use incrementation operator to add one to count variable
jamesishimwe Mar 12, 2026
554f516
declare and assign initials variable at the same time
jamesishimwe Mar 12, 2026
d8527c9
change cardNumber variable to string
jamesishimwe Mar 12, 2026
b41acf0
convert hour,minute and second to string format with two characters
jamesishimwe Mar 12, 2026
278c8d3
Implement function toPounds
jamesishimwe Mar 16, 2026
faee7b6
Answer the questions
jamesishimwe Mar 16, 2026
4d41761
add test for acute,obtuse,straight and full angles
jamesishimwe Mar 23, 2026
29e907b
complete test for obtuse angle
jamesishimwe Mar 23, 2026
83d6386
add test for straight angle
jamesishimwe Mar 23, 2026
79f9627
add test for reflex angle
jamesishimwe Mar 23, 2026
c86e2f1
add test for full angle
jamesishimwe Mar 23, 2026
bcaf210
Make corrections on angles for straight,reflex,full
jamesishimwe Mar 24, 2026
2b8c484
Write more test: negative , equal and improper fractions
jamesishimwe Mar 23, 2026
c8ef773
Write test for negative fraction
jamesishimwe Mar 23, 2026
9b82cc5
Write test for equal fraction
jamesishimwe Mar 23, 2026
25650ce
add test for zero as the numerator
jamesishimwe Mar 23, 2026
186adcd
Declare the variable rank and assign it
jamesishimwe Mar 23, 2026
d9220ae
Create card groups
jamesishimwe Mar 23, 2026
c32250e
add a test for each card group in the function
jamesishimwe Mar 23, 2026
0570e10
Add test in the function for invalid card
jamesishimwe Mar 23, 2026
3f33088
add test for card Five of Hearts
jamesishimwe Mar 23, 2026
36f28be
add test for Face cards
jamesishimwe Mar 23, 2026
9d1a257
add a test for invalid cards
jamesishimwe Mar 23, 2026
1f610e6
Install jest
jamesishimwe Mar 24, 2026
2339e5d
add jest test for acute angle
jamesishimwe Mar 24, 2026
a8cf4e3
add jest test for obtuse angle
jamesishimwe Mar 24, 2026
e6a30c0
add jest test for straight angle
jamesishimwe Mar 24, 2026
1285f30
add jest test for reflex angle
jamesishimwe Mar 24, 2026
7b89341
add jest test for improper fraction
jamesishimwe Mar 24, 2026
2cf7cf6
add jest tests for negative fractions
jamesishimwe Mar 24, 2026
6820289
add jest test for equal numerator and denominator fraction
jamesishimwe Mar 24, 2026
cca448e
add jest tests for 2-10 cards
jamesishimwe Mar 24, 2026
00705ea
add jest tests for Face cards
jamesishimwe Mar 24, 2026
a5b1a4f
add jest test for invalid cards
jamesishimwe Mar 24, 2026
8963c86
Implement function countChar
jamesishimwe Mar 24, 2026
a273c2f
add jest test for no occurances
jamesishimwe Mar 24, 2026
00bcbf2
Implement the function getOrdinalNumber
jamesishimwe Mar 24, 2026
b131ae5
Add test for 2nd
jamesishimwe Mar 24, 2026
e7469d6
Add test for 3rd
jamesishimwe Mar 24, 2026
3e910ee
Add test for 30th
jamesishimwe Mar 24, 2026
c0e3b2e
Implement function repeat
jamesishimwe Mar 24, 2026
f23f89e
Add test for count 1
jamesishimwe Mar 24, 2026
cbc9f6d
Add test for count 0
jamesishimwe Mar 24, 2026
b419f7a
Add test for count which is negative
jamesishimwe Mar 26, 2026
9b8cd1e
Undo changes to Sprint 1 folder
jamesishimwe Mar 26, 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
21 changes: 21 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,24 @@
// 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("99p"));
console.log(toPounds("5p"));
10 changes: 5 additions & 5 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ function formatTimeDisplay(seconds) {
// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// =============> It will be called 3 times, once for the hours, minutes and 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
// num is assigned the value of totalHours, which is 0 because 61 seconds is less than 1 hour.

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// The return value is "00" because pad converts the number 0 to a string and pads it to ensure it has at least 2 characters, resulting in "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
// num is assigned the value of remainingSeconds, which is 1 because 61 seconds has 1 second remaining after accounting for the full minute (60 seconds).

// 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
// The return value is "01" because pad converts the number 1 to a string and pads it to ensure it has at least 2 characters, resulting in "01".
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
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.
} else if (angle < 90) return "Acute angle";
else if (angle > 90 && angle < 180) return "Obtuse angle";
else if (angle === 180) return "Straight angle";
else if (angle > 180 && angle < 360) return "Reflex angle";
else if (angle === 360) return "Full 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.
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand Down Expand Up @@ -51,13 +55,19 @@ assertEquals(acute, "Acute angle");
// 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(210);
assertEquals(reflex, "Reflex angle");

const full = getAngleType(360);
assertEquals(full, "Full angle");
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@

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

// The line below allows us to load the isProperFraction function into tests in other files.
Expand Down Expand Up @@ -47,13 +52,16 @@ assertEquals(improperFraction, false);
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
const negativeFraction = isProperFraction(-4, 7);
// ====> complete with your assertion

assertEquals(negativeFraction, true);
// Equal Numerator and Denominator check:
// Input: numerator = 3, denominator = 3
// target output: false
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
const equalFraction = isProperFraction(3, 3);
// ====> complete with your assertion

assertEquals(equalFraction, false);
// Stretch:
// What other scenarios could you test for?
//Testing for 0 numerator
const zeroNumerator = isProperFraction(0, 2);
assertEquals(zeroNumerator, false);
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@
// 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) {
let rank = card.slice(0, 1);
if (card.slice(0, 2) === "10") rank = card.slice(0, 2);
const numberCards = ["1", "2", "3", "4", "5", "6", "7", "8", "9"];
const otherCards = ["10", "K", "J", "Q"];
if (rank === "A") {
return 11;
}
} else if (numberCards.includes(rank)) return Number(rank);
else if (otherCards.includes(rank)) return 10;
else return "Invalid Card";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should throw an error instead of returning a string (and then update the tests at the bottom)

}

// The line below allows us to load the getCardValue function into tests in other files.
Expand Down Expand Up @@ -40,12 +46,21 @@ assertEquals(aceofSpades, 11);
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
const fiveofHearts = getCardValue("5♥");
// ====> write your test here, and then add a line to pass the test in the function above

assertEquals(fiveofHearts, 5);
// Handle Face Cards (J, Q, K):
// Given a card with a rank of "10," "J," "Q," or "K",
// When the function is called with such a card,
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.

const faceCards = [
getCardValue("K♥"),
getCardValue("J♥"),
getCardValue("Q♥"),
getCardValue("10♥"),
];
assertEquals(faceCards[0], 10);
assertEquals(faceCards[1], 10);
assertEquals(faceCards[2], 10);
assertEquals(faceCards[3], 10);
// Handle Ace (A):
// Given a card with a rank of "A",
// When the function is called with an Ace,
Expand All @@ -55,3 +70,5 @@ const fiveofHearts = getCardValue("5♥");
// 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("B♠");
assertEquals(invalidCard, "Invalid Card");
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@ test("should identify right angle (90°)", () => {
// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"

test("should identify Acute angle", () => {
expect(getAngleType(45)).toEqual("Acute angle");
});
// Case 3: Identify Obtuse Angles:
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"

test("should identify Obtuse angle", () => {
expect(getAngleType(120)).toEqual("Obtuse angle");
});
// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"

test("should identify Straight angle", () => {
expect(getAngleType(180)).toEqual("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"
test("should identify Reflex angle", () => {
expect(getAngleType(210)).toEqual("Reflex angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ test("should return true for a proper fraction", () => {
});

// Case 2: Identify Improper Fractions:

test("should return false for a proper fraction", () => {
expect(isProperFraction(3, 2)).toEqual(false);
});
// Case 3: Identify Negative Fractions:

test("should return true for a proper fraction", () => {
expect(isProperFraction(-2, 3)).toEqual(true);
});
test("should return false for a proper fraction", () => {
expect(isProperFraction(-3, 2)).toEqual(false);
});
// Case 4: Identify Equal Numerator and Denominator:
test("should return false for a proper fraction", () => {
expect(isProperFraction(3, 3)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ test("should return 11 for Ace of Spades", () => {
});

// Case 2: Handle Number Cards (2-10):

test("should return number 2 for 2 of Spades", () => {
const twoOfSpades = getCardValue("2♠");
expect(twoOfSpades).toEqual(2);
});
test("should return number 8 for 8 of Spades", () => {
const eightOfSpades = getCardValue("8♠");
expect(eightOfSpades).toEqual(8);
});
// Case 3: Handle Face Cards (J, Q, K):

test("should return 10 for Face cards", () => {
const JackOfSpades = getCardValue("J♠");
expect(JackOfSpades).toEqual(10);
});
test("should return 10 for Face cards", () => {
const QueenOfSpades = getCardValue("Q♠");
expect(QueenOfSpades).toEqual(10);
});
// Case 4: Handle Ace (A):
// Case 5: Handle Invalid Cards:
test("should return Invalid Card for Invalid Cards/Other inputs", () => {
const InvalidCard = getCardValue("X");
expect(InvalidCard).toEqual("Invalid Card");
});
3 changes: 2 additions & 1 deletion Sprint-3/2-practice-tdd/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
return stringOfCharacters.split("").filter((char) => char === findCharacter)
.length;
}

module.exports = countChar;
7 changes: 7 additions & 0 deletions Sprint-3/2-practice-tdd/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ test("should count multiple occurrences of a character", () => {
});

// Scenario: No Occurrences
test("should count multiple occurrences of a character", () => {
const str = "aaaaa";
const char = "x";
const count = countChar(str, char);
expect(count).toEqual(0);
});

// Given the input string str,
// And a character char that does not exist within the case-sensitive str,
// When the function is called with these inputs,
Expand Down
9 changes: 8 additions & 1 deletion Sprint-3/2-practice-tdd/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
function getOrdinalNumber(num) {
return "1st";
if (num === 11) return "11th";
else if (num === 12) return "12th";
else if (num === 13) return "13th";
numLast = num.toString().slice(-1);
if (numLast === "1") return `${num}st`;
else if (numLast === "2") return `${num}nd`;
else if (numLast === "3") return `${num}rd`;
else return `${num}th`;
}

module.exports = getOrdinalNumber;
24 changes: 24 additions & 0 deletions Sprint-3/2-practice-tdd/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,27 @@ const getOrdinalNumber = require("./get-ordinal-number");
test("should return '1st' for 1", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
});

// Case 2: Identify the ordinal number for 2
// When the number is 2,
// Then the function should return "2nd"

test("should return '2nd' for 2", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
});

// Case 3: Identify the ordinal number for 3
// When the number is 3,
// Then the function should return "3rd"

test("should return '3rd' for 3", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
});

// Case 4: Identify the ordinal number for Other numbers ending in 4-9
// When the number is 30,
// Then the function should return "30th"

test("should return '30th' for 30", () => {
expect(getOrdinalNumber(30)).toEqual("30th");
});
8 changes: 6 additions & 2 deletions Sprint-3/2-practice-tdd/repeat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
function repeat() {
return "hellohellohello";
function repeat(str, count) {
if (count < 0) return "Invalid times";
return Array(count)
.fill(0)
.map(() => str)
.join("");
}

module.exports = repeat;
20 changes: 18 additions & 2 deletions Sprint-3/2-practice-tdd/repeat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,29 @@ test("should repeat the string count times", () => {
// Given a target string str and a count equal to 1,
// When the repeat function is called with these inputs,
// Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition.

test("should repeat the string count times", () => {
const str = "hello";
const count = 1;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("hello");
});
// case: Handle Count of 0:
// Given a target string str and a count equal to 0,
// When the repeat function is called with these inputs,
// Then it should return an empty string, ensuring that a count of 0 results in an empty output.

test("should repeat the string count times", () => {
const str = "hello";
const count = 0;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("");
});
// case: Negative Count:
// Given a target string str and a negative integer count,
// When the repeat function is called with these inputs,
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
test("should repeat the string count times", () => {
const str = "hello";
const count = -3;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("Invalid times");
});
Loading