Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4c62400
updated 1-count.js with an explanation of line 3
JorvanW Jun 10, 2026
376a6b0
added answers to 0.js
Jun 27, 2026
2323e10
Added notes for 1.js
Jun 27, 2026
87fbee5
added notes for 2.js
Jun 27, 2026
57e3a65
added notes to 0.js
Jun 29, 2026
bf5c332
added answer to 0.js
Jun 29, 2026
4ca3f91
added notes to 1.js
Jun 29, 2026
185c7e7
added answers to 2.js
Jun 29, 2026
195189a
completed. 1-bmi
Jul 4, 2026
3f957a1
Answered the questions for 2-cases.js
Jul 4, 2026
b48031e
Added answers to the questions in the time-format.js file.
Jul 8, 2026
216221a
Created code for 1-get-angle-type.js
Jul 14, 2026
d10fc3c
fixed error in 'get-angle-types' and changed "let" to "function".
Jul 14, 2026
60638b4
wrote code for "is-proper-fraction" function and added test cases for it
Jul 14, 2026
2ac2702
Added code for 1-get-angle-type.test.js to include a test case for ea…
Jul 14, 2026
f8cf7cf
added code to test 2-is-proper-fraction.test.js
Jul 14, 2026
f3f69db
Add count function and tests
Jul 15, 2026
f6f3d1d
Remove CLI-Treasure-Hunt subproject from Sprint-2
Jul 15, 2026
0bdef75
Add functions and test for get-ordinal-number.js
Jul 15, 2026
630c502
removed unnecessary code and simplified it in excersie-1.js
Jul 15, 2026
55740a4
Removed dead code in exercise-2
Jul 15, 2026
6994606
Added code for repeat-string .js
Jul 17, 2026
e54bbd5
added code for 3-get-card-value.js
Jul 22, 2026
9aaaa7e
added tests for 3-get-card-value.test.js
Jul 22, 2026
7cacfb4
added notes for 3-get-card-value.js
Jul 22, 2026
a6131ab
updated formatting errors in 1-get-angle-types and 2-is-proper-faction
Jul 22, 2026
a85a823
updated code and added tests for repeat.str
Jul 22, 2026
cc958de
removed code from Sprint-2
Aug 3, 2026
919dba4
removed line of code from sprint -1
Aug 3, 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@
// execute the code to ensure all tests pass.

function getAngleType(angle) {
{
if (angle > 0 && angle < 90) {
return "Acute angle";
}
if (angle === 90) {
return "Right angle";
}
if (angle > 90 && angle < 180) {
return "Obtuse angle";
}
if (angle === 180) {
return "Straight angle";
}
if (angle > 180 && angle < 360) {
return "Reflex angle";
}
return "Invalid angle";
}


// TODO: Implement this function
}

Expand All @@ -35,3 +55,6 @@ function assertEquals(actualOutput, targetOutput) {
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");



Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
}

// The line below allows us to load the isProperFraction function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
Expand All @@ -31,3 +28,18 @@ function assertEquals(actualOutput, targetOutput) {

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);

function isProperFraction(numerator, denominator) {
if (denominator === 0) {
return false;
}
if (numerator < denominator && numerator > 0) {
return true;
}
return false;
}
console.log(isProperFraction(2,3)); // true


module.exports = isProperFraction;

Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,31 @@
// execute the code to ensure all tests pass.

function getCardValue(card) {
// TODO: Implement this function
const suit = card.slice(-1);
const rank = card.slice(0, -1);

const validSuits = ["♠", "♥", "♦", "♣"];

if (!validSuits.includes(suit)) {
throw new Error("Invalid card");
}

if (rank === "A") {
return 11;
}

if (["J", "Q", "K"].includes(rank)) {
return 10;
}

if (["2", "3", "4", "5", "6", "7", "8", "9", "10"].includes(rank)) {
return Number(rank);
}

throw new Error("Invalid card");
}


// The line below allows us to load the getCardValue function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getCardValue;
Expand Down Expand Up @@ -52,3 +74,6 @@ try {
}

// What other invalid card cases can you think of?
// logging cards without suits to throw error


Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,36 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
});

// Case 2: Right angle
test(`should return "Right angle" when (angle === 90)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(90)).toEqual("Right angle");
});

// Case 3: Obtuse angles
// Case 4: Straight angle
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
// Test various obtuse angles, including boundary cases
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(135)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});

// Case 4: Straight angle
test(`should return "Straight angle" when (angle === 180)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(180)).toEqual("Straight angle");
});

// Case 5: Reflex angles
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
// Test various reflex angles, including boundary cases
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});

// Case 6: Invalid angles
test(`should return "Invalid angle" when (angle < 0 || angle > 360)`, () => {
// Test various invalid angles
expect(getAngleType(-1)).toEqual("Invalid angle");
expect(getAngleType(361)).toEqual("Invalid angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,31 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

test(`should return false when numerator is zero`, () => {
expect(isProperFraction(0, 1)).toEqual(false);
});

test(`should return false when numerator is negative`, () => {
expect(isProperFraction(-1, 2)).toEqual(false);
});

test(`should return false when denominator is negative`, () => {
expect(isProperFraction(1, -2)).toEqual(false);
});

test(`should return false when both numerator and denominator are negative`, () => {
expect(isProperFraction(-1, -2)).toEqual(false);
});

test(`should return true when numerator is less than denominator`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});

test(`should return false when numerator is equal to denominator`, () => {
expect(isProperFraction(2, 2)).toEqual(false);
});

test(`should return false when numerator is greater than denominator`, () => {
expect(isProperFraction(3, 2)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,28 @@ test(`Should return 11 when given an ace card`, () => {
});

// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
// Face Cards (J, Q, K)
// Invalid Cards
// Case 2 Number Cards (2-10)
test(`Should return the same number when given a number card of any suit`, () => {
expect(getCardValue("3♠")).toEqual(3);
});

// Case 3 Face Cards (J, Q, K)
test(`Should return 10 when given an any face card`, () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("Q♥")).toEqual(10)
expect(getCardValue("K♦")).toEqual(10)
});


// Invalid Cards
// test(`Cards without suits return as Invalid card`, () => {
// expect(getCardValue("10")).toEqual(new Error);
// });
test('Cards without suits return as Invalid card', () => {
expect(() => {
getCardValue("10");
}).toThrow("Invalid card");
});
// To learn how to test whether a function throws an error as expected in Jest,
// please refer to the Jest documentation:
// https://jestjs.io/docs/expect#tothrowerror
Expand Down
8 changes: 7 additions & 1 deletion Sprint-3/2-practice-tdd/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
let count = 0
for (const char of stringOfCharacters) {
if (char === findCharacter) {
count++
}
}
return count
}

module.exports = countChar;
14 changes: 14 additions & 0 deletions Sprint-3/2-practice-tdd/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ test("should count multiple occurrences of a character", () => {
// And a character `char` that does not exist within `str`.
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of `char` were found.

test("should return 0 when character is not found", () => {
const str = "hello";
const char = "z";
const count = countChar(str, char);
expect(count).toEqual(0);
});

test("should return the number of occurrences of a character in a string with different characters", () => {
const str = "london";
const char = "o";
const count = countChar(str, char);
expect(count).toEqual(2);
});
8 changes: 7 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,11 @@
function getOrdinalNumber(num) {
return "1st";
if (num % 100 === 11) {
return num + "th";
} else if (num % 10 === 1) {
return num + "st";
} else {
return num
}
}

module.exports = getOrdinalNumber;
7 changes: 7 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 @@ -18,3 +18,10 @@ test("should append 'st' for numbers ending with 1, except those ending with 11"
expect(getOrdinalNumber(21)).toEqual("21st");
expect(getOrdinalNumber(131)).toEqual("131st");
});

// Case 2: Numbers ending with 11
test("should append 'th' for numbers ending with 11", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(111)).toEqual("111th");
expect(getOrdinalNumber(211)).toEqual("211th");
});
18 changes: 13 additions & 5 deletions Sprint-3/2-practice-tdd/repeat-str.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
function repeatStr() {
// Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat).
// The goal is to re-implement that function, not to use it.
return "hellohellohello";
}
function repeatStr(str, times) {
if (times === 0) {
return "";
} else if (times < 0) {
throw new Error("error");
}

let repeatedString = "";
for (let i = 0; i < times; i++) {
repeatedString += str;
}
return repeatedString;
}

module.exports = repeatStr;
23 changes: 23 additions & 0 deletions Sprint-3/2-practice-tdd/repeat-str.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,35 @@ test("should repeat the string count times", () => {
// When the repeatStr function is called with these inputs,
// Then it should return the original `str` without repetition.

test("should return the original string when count is 1", () => {
const str = "world";
const count = 1;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("world");
});

// Case: Handle count of 0:
// Given a target string `str` and a `count` equal to 0,
// When the repeatStr function is called with these inputs,
// Then it should return an empty string.

test("should return an empty string when count is 0", () => {
const str = "world";
const count = 0;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("");
});

// Case: Handle negative count:
// Given a target string `str` and a negative integer `count`,
// When the repeatStr function is called with these inputs,
// Then it should throw an error, as negative counts are not valid.

test("should throw an error when count is negative", () => {
const str = "world";
const count = -1;

expect(() => {
repeatStr(str, count);
}).toThrow("error");
});
6 changes: 1 addition & 5 deletions Sprint-3/3-dead-code/exercise-1.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
// Find the instances of unreachable and redundant code - remove them!
// The sayHello function should continue to work for any reasonable input it's given.

let testName = "Jerry";
let testName = "Aman";
const greeting = "hello";

function sayHello(greeting, name) {
const greetingStr = greeting + ", " + name + "!";
return `${greeting}, ${name}!`;
console.log(greetingStr);
}

testName = "Aman";

const greetingMessage = sayHello(greeting, testName);

console.log(greetingMessage); // 'hello, Aman!'
5 changes: 0 additions & 5 deletions Sprint-3/3-dead-code/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
// The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable.

const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"];
const capitalisedPets = pets.map((pet) => pet.toUpperCase());
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");

function logPets(petsArr) {
petsArr.forEach((pet) => console.log(pet));
}

function countAndCapitalisePets(petsArr) {
const petCount = {};

Expand Down
Loading