-
-
Notifications
You must be signed in to change notification settings - Fork 197
WM | 25-ITP-May | Nahom Mesfin | Sprint 3 coursework #677
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
8a71bce
8fd2f67
2e81878
d7a2194
0e7248d
fbfed67
5da6652
ea11d01
4aee0b5
54df67f
e26f209
06d77a2
ffcc342
cb2c7cc
89b1da0
21da96e
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,5 +1,9 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
const rank = card.slice(0, -1); // all characters except last | ||
if (rank === "A") return 11; | ||
if (rank >= '2' && rank <= '9') return Number(rank); | ||
if (rank === "10" || rank === "J" || rank === "Q" || rank === "K") return 10; | ||
throw new Error("Invalid card rank."); | ||
} | ||
module.exports = getCardValue; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
let count = 0; | ||
for (let i = 0; i < stringOfCharacters.length; i++) { | ||
if (stringOfCharacters[i] === findCharacter) { | ||
count++; | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
module.exports = countChar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
function getOrdinalNumber(num) { | ||
return "1st"; | ||
const lastDigit = num % 10; | ||
const lastTwoDigits = num % 100; | ||
|
||
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) | ||
return num + "th"; | ||
|
||
if (lastDigit === 1) return num + "st"; | ||
if (lastDigit === 2) return num + "nd"; | ||
if (lastDigit === 3) return num + "rd"; | ||
return num + "th"; | ||
} | ||
|
||
module.exports = getOrdinalNumber; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
function repeat() { | ||
return "hellohellohello"; | ||
function repeat(str, count) { | ||
if (count < 0) { | ||
throw new Error("Count must be a non-negative integer."); | ||
} | ||
return str.repeat(count); | ||
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. What about your error condition you are testing for? 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. Yes, i should have added an error conditon to throw an error. I have added an error that throws a negative integer.
|
||
} | ||
|
||
module.exports = repeat; |
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.
In english we would say "21st" - can you make your code work in these general cases too?
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.
I have updated the function to include cases like 21st, 22nd and so on. I have used a modulo operator to get the last digits of the numbers
num % 10;
andnum % 100;
and used them to determine the cases for each number.