Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 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
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
18 changes: 14 additions & 4 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
// Predict and explain first...
// =============> write your prediction here
//we should have an error showing that str already exists so we cannot declare it again inside 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) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
//function capitalise(str) {
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
// return str;
//}

//console.log(capitalise("cat"));

// =============> write your explanation here
//str has been passed down as a parameter so we cannot declare it again. we would need to declare a different variable name.
// =============> write your new code here
function capitalise(str) {
let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`;
return capitalisedStr;
}

console.log(capitalise("cat"));
8 changes: 5 additions & 3 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

// Why will an error occur when this program runs?
// =============> write your prediction here
//decimalNumber does not exist outside the scope of the convertToPercentage funtion so the log will throw an error saying it has not been declared.

// Try playing computer with the example to work out what is going on

function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
//const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;

return percentage;
}

console.log(decimalNumber);
console.log(convertToPercentage(0.5));

// =============> write your explanation here

//decimalNumber is passed as a parameter when the function is called, line 10 tries to declare it again and assign it a new fixed value. we would need to remove that line so we can use the value passed in with the function call.
//decimalNumber only exists inside the function scope so console.log cannot access it an error will be thrown. we need to instead pass the function to console.log.
// Finally, correct the code to fix the problem
// =============> write your new code here
17 changes: 10 additions & 7 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@

// 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
//it will throw an error for use of a primitive value instead of a variable.

function square(3) {
return num * num;
}
//function square(3) {
// return num * num;
//}

// =============> write the error message here
// =============> write the error message here, SyntaxError: Unexpected number

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

//this error message is becasue we cannot pass a direct value to a function when creating it but rather when we call it. Instead we need to give it a parameter that can then hold the value that we want to pass to the function.
// Finally, correct the code to fix the problem

// =============> write your new code here
function square(num) {
return num * num;
}


console.log(square(3));
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
function getAngleType(angle) {
if (angle === 90) {
return "Right angle";
} 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";
}
// 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.
// 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 +59,16 @@ 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(270);
assertEquals(reflex, "Reflex angle");
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
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 Expand Up @@ -45,15 +51,20 @@ assertEquals(improperFraction, false);
// Input: numerator = -4, denominator = 7
// target output: true
// 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);
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?
//we can test if the numerator is 0
const zeroFraction = isProperFraction(0, 4);
assertEquals(zeroFraction, false);
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,20 @@
// 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) {
if (rank === "A") {
let rank = "";

for (let i = 0; i < card.length - 1; i++) {
rank += card[i];
}

if (Number.isInteger(Number(rank)) && Number(rank) > 1 && Number(rank) < 10) {
return Number(rank);
} else if (rank === "10" || rank === "J" || rank === "Q" || rank === "K") {
return 10;
} else if (rank === "A") {
return 11;
} else {
return "Invalid card rank.";
}
}

Expand Down Expand Up @@ -38,20 +50,25 @@ assertEquals(aceofSpades, 11);
// Given a card with a rank between "2" and "9",
// When the function is called with such a card,
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
const fiveofHearts = getCardValue("5♥");
const fiveofHearts = getCardValue("9♥");
// ====> write your test here, and then add a line to pass the test in the function above

assertEquals(fiveofHearts, 9);
// 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("J♥");
assertEquals(faceCards, 10);
// Handle Ace (A):
// Given a card with a rank of "A",
// When the function is called with an Ace,
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack.
const ace = getCardValue("A♥");
assertEquals(ace, 11);

// Handle Invalid Cards:
// 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("100♠");
assertEquals(invalidCard, "Invalid card rank.");
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,27 @@ 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 (90°<)", () => {
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 (>90° && 180°<)", () => {
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 (180°)", () => {
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 (> 180° && < 360°)", () => {
expect(getAngleType(270)).toEqual("Reflex angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@ 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);
});

// 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,12 +2,28 @@
// 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 number cards", () => {
const numberCard = getCardValue("5♠");
expect(numberCard).toEqual(5);
});
// Case 3: Handle Face Cards (J, Q, K):
test("should return 10 for Face Cards", () => {
const faceCard = getCardValue("10♠");
expect(faceCard).toEqual(10);
});
// Case 4: Handle Ace (A):
test("should return 11 for Ace", () => {
const aceCard = getCardValue("A◆");
expect(aceCard).toEqual(11);
});
// Case 5: Handle Invalid Cards:
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.");
});
Loading