-
-
Notifications
You must be signed in to change notification settings - Fork 245
West Midlands | ITP-Sept-25 | Mustaf Asani | Sprint 3 | Coursework/sprint 3 implement and rewrite #795
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
base: main
Are you sure you want to change the base?
West Midlands | ITP-Sept-25 | Mustaf Asani | Sprint 3 | Coursework/sprint 3 implement and rewrite #795
Changes from 3 commits
26fd354
5ab6322
0c7cc6f
cc216e1
90013dc
f63f7cf
a02b0c5
e097316
742c228
0d5ad45
2038048
7daf16b
dfebb97
6865348
43d650c
3ca95c6
c56bd67
2765c49
035e27e
50ee9ef
bcbd867
137fd7c
e5b18e4
5fa3d08
d58910a
8b52886
78f21df
8ad9d08
14ddfad
1a5aada
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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)}`); |
| 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)}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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]; | ||
| } | ||
|
||
|
|
||
| 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; | ||
|
|
@@ -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 |
|---|---|---|
|
|
@@ -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); | ||
|
||
| }); | ||
|
|
||
| // 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 |
|---|---|---|
|
|
@@ -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); | ||
|
||
| }); | ||
| // Case 3: Handle Face Cards (J, Q, K): | ||
| test("should return 10 for Face Cards", () => { | ||
| const faceCard = getCardValue("K♠"); | ||
| const faceCard = getCardValue("10♠"); | ||
|
||
| expect(faceCard).toEqual(10); | ||
| }); | ||
| // Case 4: Handle Ace (A): | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. combined the tests and added more tests for different values |
||
Uh oh!
There was an error while loading. Please reload this page.