Skip to content

London | ITP-May-2025 | Seddiq Azam | Module-Structuring-and-Testing-Data | Sprint-3 #621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
801370c
modified: Sprint-3/1-key-implement/1-get-angle-type.js
sedazam Jun 25, 2025
783668e
modified: Sprint-3/1-key-implement/1-get-angle-type.js
sedazam Jun 25, 2025
38f709c
modified: Sprint-3/1-key-implement/2-is-proper-fraction.js
sedazam Jun 27, 2025
639f8b3
modified: Sprint-3/1-key-implement/3-get-card-value.js
sedazam Jun 27, 2025
a226acb
modified: Sprint-3/1-key-implement/2-is-proper-fraction.js
sedazam Jun 27, 2025
7d6581e
modified: Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
sedazam Jun 27, 2025
d7205b2
modified: Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js
sedazam Jun 27, 2025
59f3d57
modified: Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
sedazam Jun 27, 2025
2c59948
modified: Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js
sedazam Jun 27, 2025
9e9c806
modified: Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
sedazam Jun 28, 2025
7d1152b
modified: Sprint-3/2-mandatory-rewrite/3-get-card-value.js
sedazam Jun 28, 2025
b3b9169
modified: Sprint-3/3-mandatory-practice/implement/count.js
sedazam Jun 28, 2025
ce039c5
modified: Sprint-3/3-mandatory-practice/implement/get-ordinal-numb…
sedazam Jun 28, 2025
898a396
modified: Sprint-3/3-mandatory-practice/implement/repeat.js
sedazam Jun 28, 2025
9e4a1ce
modified: Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js
sedazam Jun 28, 2025
37aea1b
modified: Changes made if angles are <0 or >360 must return invalid …
sedazam Jul 7, 2025
84dbda7
modified: Changed parseInt to Number(str) Sprint-3/2-mandatory-rewr…
sedazam Jul 7, 2025
a62c043
modified: Sprint-3/3-mandatory-practice/implement/get-ordinal-numb…
sedazam Jul 8, 2025
8d1a9d8
modified: Updated the test description Sprint-3/3-mandatory-practice…
sedazam Jul 8, 2025
0ccc994
modified: Fixed isProperFraction(-2, 3) should return true Sprint-…
sedazam Jul 8, 2025
f6376ea
modified: Sprint-3/2-mandatory-rewrite/3-get-card-value.js
sedazam Jul 8, 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
40 changes: 37 additions & 3 deletions Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
// Then, write the next test! :) Go through this process until all the cases are implemented

function getAngleType(angle) {
if (angle === 90) return "Right angle";
// read to the end, complete line 36, then pass your test here
if (angle === 90) return "Right angle";
if (angle > 0 && angle < 90) return "Acute angle";
if (angle > 90 && angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
if (angle > 180 && angle < 360) return "Reflex angle";

// read to the end, complete line 36, then pass your test here
}

// we're going to use this helper function to make our assertions easier to read
Expand Down Expand Up @@ -43,14 +48,43 @@ assertEquals(acute, "Acute angle");
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"
const obtuse = getAngleType(120);
assertEquals(obtuse, "Obtuse angle");
// ====> write your test here, and then add a line to pass the test in the function above

// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"
const straight = getAngleType(180);
assertEquals(straight, "Straight angle");
// ====> write your test here, and then add a line to pass the test in the function above

// 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
const reflex = getAngleType(270);
assertEquals(reflex, "Reflex angle");
// ====> write your test here, and then add a line to pass the test in the function above

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/tempCodeRunnerFile.js"
// /Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/tempCodeRunnerFile.js:1
// node 1-get-angle-type.js
// ^

// SyntaxError: Unexpected number
// at wrapSafe (node:internal/modules/cjs/loader:1662:18)
// at Module._compile (node:internal/modules/cjs/loader:1704:20)
// at Object..js (node:internal/modules/cjs/loader:1895:10)
// at Module.load (node:internal/modules/cjs/loader:1465:32)
// at Function._load (node:internal/modules/cjs/loader:1282:12)
// at TracingChannel.traceSync (node:diagnostics_channel:322:14)
// at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
// at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
// at node:internal/main/run_main_module:36:49
//
// Node.js v22.16.0
//
//[Done] exited with code=1 in 0.051 seconds

//[Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/1-get-angle-type.js"

// [Done] exited with code=0 in 0.05 seconds
55 changes: 53 additions & 2 deletions Sprint-3/1-key-implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (numerator < denominator) return true;
if (numerator >= denominator || denominator <= 0) return false;
return false;
}

// here's our helper again
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
`Assertion failed: ${actualOutput} !== ${targetOutput}. ``Expected ${actualOutput} to equal ${targetOutput}`
);
}

Expand All @@ -41,13 +43,62 @@ 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?
const zeroNumerator = isProperFraction(0, 5);
assertEquals(zeroNumerator, true); // 0/5 is a proper fraction

const zeroDenominator = isProperFraction(5, 0);
assertEquals(zeroDenominator, false); // 5/0 is not a proper fraction

const negativeDenominator = isProperFraction(3, -4);
assertEquals(negativeDenominator, false); // 3/-4 is not a proper fraction

const negativeFractionBoth = isProperFraction(-3, -4);
assertEquals(negativeFractionBoth, true); // -3/-4 is a proper fraction

const largeNumerator = isProperFraction(1, 1000);
assertEquals(largeNumerator, true); // 1/1000 is a proper fraction

const largeDenominator = isProperFraction(1000, 1);
assertEquals(largeDenominator, false); // 1000/1 is not a proper

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/2-is-proper-fraction.js"
// Assertion failed: Expected undefined to equal false

// [Done] exited with code=0 in 0.859 seconds

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/2-is-proper-fraction.js"
// Assertion failed: Expected undefined to equal false

// [Done] exited with code=0 in 0.054 seconds

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/2-is-proper-fraction.js"
// Assertion failed: Expected undefined to equal false

// [Done] exited with code=0 in 0.052 seconds

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/2-is-proper-fraction.js"
// Assertion failed: Expected undefined to equal false

// [Done] exited with code=0 in 0.054 seconds

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/2-is-proper-fraction.js"
// Assertion failed: Expected undefined to equal false

// [Done] exited with code=0 in 0.053 seconds

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/2-is-proper-fraction.js"
// Assertion failed: Assertion failed: false !== true. Check your function isProperFraction. You may need to fix your code or the test case. If you think your code is correct, check the test case. If the test case is correct, check your function. Expected false to equal true

// [Done] exited with code=0 in 0.035 seconds
184 changes: 181 additions & 3 deletions Sprint-3/1-key-implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
// 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") return 11;
let rank = card.slice(0, -1); // Get the rank part of the card (everything except the last character)
if (rank === "A") return 11;
if (rank === "K" || rank === "Q" || rank === "J" || rank === "10") return 10;
if (rank >= "2" && rank <= "9") return parseInt(rank, 10);
throw new Error("Invalid card rank.");
}

// You need to write assertions for your function to check it works in different cases
Expand All @@ -27,14 +31,13 @@ function assertEquals(actualOutput, targetOutput) {
// Then it should return the numerical card value
const aceofSpades = getCardValue("A♠");
assertEquals(aceofSpades, 11);

// Handle Number Cards (2-10):
// 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♥");
// ====> 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,
Expand All @@ -49,3 +52,178 @@ 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."

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js"
// /Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:11
// if (rank === "A") return 11;
// ^

// ReferenceError: rank is not defined
// at getCardValue (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:11:5)
// at Object.<anonymous> (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:28:21)
// at Module._compile (node:internal/modules/cjs/loader:1730:14)
// at Object..js (node:internal/modules/cjs/loader:1895:10)
// at Module.load (node:internal/modules/cjs/loader:1465:32)
// at Function._load (node:internal/modules/cjs/loader:1282:12)
// at TracingChannel.traceSync (node:diagnostics_channel:322:14)
// at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
// at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
// at node:internal/main/run_main_module:36:49

// Node.js v22.16.0

// [Done] exited with code=1 in 0.052 seconds

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js"
// /Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:11
// if (rank === "A") return 11;
// ^

// ReferenceError: rank is not defined
// at getCardValue (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:11:5)
// at Object.<anonymous> (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:28:21)
// at Module._compile (node:internal/modules/cjs/loader:1730:14)
// at Object..js (node:internal/modules/cjs/loader:1895:10)
// at Module.load (node:internal/modules/cjs/loader:1465:32)
// at Function._load (node:internal/modules/cjs/loader:1282:12)
// at TracingChannel.traceSync (node:diagnostics_channel:322:14)
// at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
// at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
// at node:internal/main/run_main_module:36:49

// Node.js v22.16.0

// [Done] exited with code=1 in 0.049 seconds

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js"
// /Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:11
// if (rank === "A") return 11;
// ^

// ReferenceError: rank is not defined
// at getCardValue (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:11:5)
// at Object.<anonymous> (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:28:21)
// at Module._compile (node:internal/modules/cjs/loader:1730:14)
// at Object..js (node:internal/modules/cjs/loader:1895:10)
// at Module.load (node:internal/modules/cjs/loader:1465:32)
// at Function._load (node:internal/modules/cjs/loader:1282:12)
// at TracingChannel.traceSync (node:diagnostics_channel:322:14)
// at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
// at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
// at node:internal/main/run_main_module:36:49

// Node.js v22.16.0

// [Done] exited with code=1 in 0.053 seconds

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/tempCodeRunnerFile.js"
// /Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/tempCodeRunnerFile.js:1
// if (rank === "A") return 11;
// ^

// ReferenceError: rank is not defined
// at Object.<anonymous> (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/tempCodeRunnerFile.js:1:5)
// at Module._compile (node:internal/modules/cjs/loader:1730:14)
// at Object..js (node:internal/modules/cjs/loader:1895:10)
// at Module.load (node:internal/modules/cjs/loader:1465:32)
// at Function._load (node:internal/modules/cjs/loader:1282:12)
// at TracingChannel.traceSync (node:diagnostics_channel:322:14)
// at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
// at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
// at node:internal/main/run_main_module:36:49

// Node.js v22.16.0

// [Done] exited with code=1 in 0.051 seconds

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js"
// /Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:11
// if (rank === "A") return 11;
// ^

// ReferenceError: rank is not defined
// at getCardValue (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:11:5)
// at Object.<anonymous> (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:28:21)
// at Module._compile (node:internal/modules/cjs/loader:1730:14)
// at Object..js (node:internal/modules/cjs/loader:1895:10)
// at Module.load (node:internal/modules/cjs/loader:1465:32)
// at Function._load (node:internal/modules/cjs/loader:1282:12)
// at TracingChannel.traceSync (node:diagnostics_channel:322:14)
// at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
// at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
// at node:internal/main/run_main_module:36:49

// Node.js v22.16.0

// [Done] exited with code=1 in 0.05 seconds

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js"
// /Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:11
// if (rank === "A") return 11;
// ^

// ReferenceError: rank is not defined
// at getCardValue (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:11:5)
// at Object.<anonymous> (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:28:21)
// at Module._compile (node:internal/modules/cjs/loader:1730:14)
// at Object..js (node:internal/modules/cjs/loader:1895:10)
// at Module.load (node:internal/modules/cjs/loader:1465:32)
// at Function._load (node:internal/modules/cjs/loader:1282:12)
// at TracingChannel.traceSync (node:diagnostics_channel:322:14)
// at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
// at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
// at node:internal/main/run_main_module:36:49

// Node.js v22.16.0

// [Done] exited with code=1 in 0.052 seconds

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js"
// /Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:11
// if (rank === "A") return 11;
// ^

// ReferenceError: rank is not defined
// at getCardValue (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:11:5)
// at Object.<anonymous> (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:28:21)
// at Module._compile (node:internal/modules/cjs/loader:1730:14)
// at Object..js (node:internal/modules/cjs/loader:1895:10)
// at Module.load (node:internal/modules/cjs/loader:1465:32)
// at Function._load (node:internal/modules/cjs/loader:1282:12)
// at TracingChannel.traceSync (node:diagnostics_channel:322:14)
// at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
// at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
// at node:internal/main/run_main_module:36:49

// Node.js v22.16.0

// [Done] exited with code=1 in 0.045 seconds

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js"
// /Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:11
// if (rank === "A") return 11;
// ^

// ReferenceError: rank is not defined
// at getCardValue (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:11:5)
// at Object.<anonymous> (/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js:28:21)
// at Module._compile (node:internal/modules/cjs/loader:1730:14)
// at Object..js (node:internal/modules/cjs/loader:1895:10)
// at Module.load (node:internal/modules/cjs/loader:1465:32)
// at Function._load (node:internal/modules/cjs/loader:1282:12)
// at TracingChannel.traceSync (node:diagnostics_channel:322:14)
// at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
// at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
// at node:internal/main/run_main_module:36:49

// Node.js v22.16.0

// [Done] exited with code=1 in 0.054 seconds

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js"

// [Done] exited with code=0 in 0.052 seconds

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/1-key-implement/3-get-card-value.js"

// [Done] exited with code=0 in 0.052 seconds
23 changes: 13 additions & 10 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
function getAngleType(angle) {
if (typeof angle !== "number" || angle <= 0 || angle > 360) {
return "Invalid angle";
}
if (angle < 90) return "Acute angle";
if (angle === 90) return "Right angle";
if (angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
return "Reflex angle";
// replace with your completed function from key-implement

}








// Don't get bogged down in this detail
// Jest uses CommonJS module syntax by default as it's quite old
// We will upgrade our approach to ES6 modules in the next course module, so for now
// We will upgrade our approach to ES6 modules in the next course module, so for now
// we have just written the CommonJS module.exports syntax for you
module.exports = getAngleType;
module.exports = getAngleType;

// [Running] node "/Users/seddiqazam/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js"

// [Done] exited with code=0 in 0.051 seconds
Loading