-
-
Notifications
You must be signed in to change notification settings - Fork 219
London_ITP_Jan|Aung_Ye_Kyaw |Module-Structuring-Testing-Data |Coursework/sprint 3 #329
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
Changes from 45 commits
7ce428b
6442b27
b31a592
8f67390
abbe390
03caef7
c8d6e99
da12dc5
713cbf9
2b9bd4e
73fec8d
b352caf
6a87825
aa2898b
ccd7540
9230d74
b7a5527
489ba23
e55312c
0f67671
9e4d56b
11b6519
7ea8f44
b1f54f7
91e9e28
f05fc9a
d6fea99
67f6a60
d07cfb0
c784ca5
da915e1
577b9e6
67e1651
0c3f7af
41fc8bd
f5a5ee2
4893386
541ddf2
489ad20
618ab0b
26fd07c
75240a8
aba23f6
81cb2c5
a12d680
f16df6e
ea3e114
b4066a2
648adf7
da614be
8a90ce6
65ad614
a8c26e6
9ed5a3e
9fba579
0620564
f00ef51
42d22c1
8bc74aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,51 @@ | |
// complete the rest of the tests and cases | ||
// 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 cards = card.slice(0,-1); // drop one last letter from string | ||
|
||
|
||
const faceCards = ["J","Q","K"]; | ||
|
||
if (cards === "A") // if the input is A return 11 | ||
{ | ||
return 11; | ||
} | ||
else if (card == "Ace") // if the input is Ace return 11 | ||
{ | ||
return 11; | ||
} | ||
|
||
else if (cards.length ==1 && faceCards.includes(cards) ) // input length is 1 and input is in rank 1 return 10; | ||
cjyuan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
{ | ||
return 10; | ||
} | ||
|
||
else if (cards === "10") // if input is 10 return 10; | ||
{ | ||
return 10; | ||
} | ||
|
||
|
||
else if (cards.length ==1 && faceCards.includes(cards)=== false) // if input length is 1 & not include in rank1 | ||
cjyuan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
{ | ||
value = Number(cards); | ||
if (value == 0 || faceCards.includes(cards)=== false) | ||
{ | ||
return 'The card is invalid'; | ||
} // convert the input into number and return the value | ||
return value; | ||
} | ||
|
||
else if (cards.length >=2 && cards != "10") // if input length is 2 and not equal to 10 return invalid | ||
cjyuan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
{ | ||
return `The card is invalid`; | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
|
||
// You need to write assertions for your function to check it works in different cases | ||
|
@@ -27,25 +70,52 @@ function assertEquals(actualOutput, targetOutput) { | |
// Then it should return the numerical card value | ||
const aceofSpades = getCardValue("A♠"); | ||
assertEquals(aceofSpades, 11); | ||
console.log(`A is equal to ${aceofSpades}`); | ||
|
||
// 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♥"); | ||
assertEquals(fiveofHearts,5); | ||
console.log(`The result is ${fiveofHearts}`); | ||
|
||
const twofHearts = getCardValue("2♥"); | ||
assertEquals(twofHearts,2); | ||
console.log(`The result is ${twofHearts}`); | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
|
||
// 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 jack = getCardValue("J♥"); | ||
assertEquals(jack,10); | ||
console.log(`J is equal to ${jack}`); | ||
|
||
const tenHeart = getCardValue("10♥"); | ||
assertEquals(tenHeart,10); | ||
console.log(`The result is ${tenHeart}`); | ||
// 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("Ace"); | ||
assertEquals(Ace,11); | ||
console.log(`The result is ${Ace}`); | ||
// 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 invalidNumber = getCardValue("15♠"); | ||
console.log("15 space is",`${invalidNumber}`); | ||
|
||
const invalidNumber1 = getCardValue("0♠"); | ||
console.log(`${invalidNumber1}`); | ||
|
||
const invalidNumber2 = getCardValue("B♠"); | ||
console.log(`${invalidNumber2}`); | ||
|
||
const invalidNumber3 = getCardValue("123♠"); | ||
console.log(`${invalidNumber3}`); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
} | ||
if (numerator < denominator) | ||
{ | ||
return true; | ||
} | ||
else if (numerator<0 && denominator<0) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
|
||
} | ||
|
||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,44 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
|
||
|
||
let cards = card.slice(0,-1); // drop one last letter from string | ||
|
||
const rank1= ["J","Q","K"]; | ||
|
||
if (cards === "A") // if the input is A return 11 | ||
{ | ||
return 11; | ||
} | ||
else if (card == "Ace") // if the input is Ace return 11 | ||
{ | ||
return 11; | ||
} | ||
|
||
else if (cards.length ==1 && rank1.includes(cards) ) // input length is 1 and input is in rank 1 return 10; | ||
{ | ||
return 10; | ||
} | ||
|
||
else if (cards === "10") // if input is 10 return 10; | ||
{ | ||
return 10; | ||
} | ||
|
||
|
||
else if (cards.length ==1 && rank1.includes(cards)=== false) // if input length is 1 & not include in rank1 | ||
{ | ||
value = Number(cards); // convert the input into number and return the value | ||
return value; | ||
} | ||
|
||
else if (cards.length ==2 && cards != "10") // if input length is 2 and not equal to 10 return invalid | ||
{ | ||
return `The card is invalid`; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} | ||
module.exports = getCardValue; |
Uh oh!
There was an error while loading. Please reload this page.