-
-
Notifications
You must be signed in to change notification settings - Fork 197
West Midlands | 25-ITP-May | Mustaf Asani | Module-Structuring-and -Testing-Data | Sprint 3 #679
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?
Changes from all commits
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 |
---|---|---|
|
@@ -8,7 +8,16 @@ | |
// 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; | ||
const rank = card.slice(0, -1); // Get the rank part of the card (everything except the last character) | ||
if (rank === "A") { | ||
return 11; | ||
} else if (rank === "K" || rank === "Q" || rank === "J" || rank === "10") { | ||
return 10; | ||
}else if (rank >= "2" && rank <= "9") { | ||
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. If I give it a strange value like "222♥" what would you expect the output to be? What actually happens? |
||
return parseInt(rank); | ||
}else { | ||
return "Invalid card rank."; | ||
} | ||
} | ||
|
||
// You need to write assertions for your function to check it works in different cases | ||
|
@@ -34,11 +43,14 @@ 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 kingOfDiamonds = getCardValue("K♦"); | ||
assertEquals(kingOfDiamonds, 10); | ||
|
||
// Handle Ace (A): | ||
// Given a card with a rank of "A", | ||
|
@@ -49,3 +61,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("Z♣"); | ||
assertEquals(invalidCard, "Invalid card rank."); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
if (Math.abs(numerator) < Math.abs(denominator)) return true; | ||
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. This is a more correct solution - you may want to use it in your earlier task |
||
// add your completed function from key-implement here | ||
if (Math.abs(numerator) >= Math.abs(denominator)) return false; | ||
// Handle edge cases | ||
if (denominator === 0) return false; // Denominator cannot be zero | ||
if (numerator === 0) return true; // Zero numerator is a proper fraction | ||
return false; // Default case for any other conditions | ||
} | ||
|
||
|
||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
const rank = card.slice(0, -1); // Get the rank part of the card (everything except the last character) | ||
if (rank === "A") { | ||
return 11; | ||
} else if (rank === "K" || rank === "Q" || rank === "J" || rank === "10") { | ||
return 10; | ||
}else if (rank >= "2" && rank <= "9") { | ||
return parseInt(rank); | ||
}else { | ||
return "Invalid card rank."; | ||
} | ||
} | ||
module.exports = getCardValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if I give it a negative improper fraction, like -20/2?