Skip to content

Commit 0b2698a

Browse files
author
Enice-Codes
committed
corrected and tested all my code
1 parent 7fbed1b commit 0b2698a

4 files changed

Lines changed: 49 additions & 33 deletions

File tree

Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,19 @@
1414
// Acceptance criteria:
1515
// After you have implemented the function, write tests to cover all the cases, and
1616
// execute the code to ensure all tests pass.
17-
1817
function getAngleType(angle) {
19-
// TODO: Implement this function
2018
if (angle > 0 && angle < 90)
21-
return "Acute angle";
19+
return "Acute angle";
2220
else if (angle === 90)
23-
return "Right angle";
21+
return "right angle";
2422
else if (angle > 90 && angle < 180)
25-
return "obtuse angle";
23+
return "obtuse angle";
2624
else if (angle === 180)
27-
return "Straight angle";
25+
return "straight angle";
2826
else if (angle > 180 && angle < 360)
29-
return "Reflex angle";
27+
return "reflex angle";
3028
else
31-
return "Invalid angle";
32-
29+
return "Invalid angle";
3330
}
3431

3532
// The line below allows us to load the getAngleType function into tests in other files.
@@ -48,7 +45,7 @@ function assertEquals(actualOutput, targetOutput) {
4845
// TODO: Write tests to cover all cases, including boundary and invalid cases.
4946
// Example: Identify Right Angles
5047
const right = getAngleType(90);
51-
assertEquals(right, "Right angle");
48+
assertEquals(right, "right angle");
5249

5350
const acute = getAngleType(45);
5451
assertEquals(acute, 'Acute angle');
@@ -57,10 +54,10 @@ const obtuse = getAngleType(120);
5754
assertEquals(obtuse,'obtuse angle')
5855

5956
const straight = getAngleType(180);
60-
assertEquals(straight, 'Straight angle');
57+
assertEquals(straight, 'straight angle');
6158

6259
const reflex = getAngleType(270);
63-
assertEquals(reflex, 'Reflex angle');
60+
assertEquals(reflex, 'reflex angle');
6461

6562
const invalid1 = getAngleType(-10);
6663
assertEquals(invalid1, 'Invalid angle');

Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
1515
if (denominator === 0){
16-
return fasle;
16+
return false;
1717

1818
}
1919
if (numerator < denominator && numerator > 0){
@@ -40,7 +40,7 @@ function assertEquals(actualOutput, targetOutput) {
4040
// Example: 1/2 is a proper fraction
4141
assertEquals(isProperFraction(1, 2), true);
4242

43-
// exapmle : 4/3 is not a proper fraction
43+
// example: 4/3 is not a proper fraction
4444
assertEquals(isProperFraction(4, 3), false);
4545

4646
// example: 6/5 is not a proper fraction

Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,21 @@
2222
// execute the code to ensure all tests pass.
2323

2424
function getCardValue(card) {
25-
// TODO: Implement this function
26-
if(card === "A♠" || card === "A♥" || card === "A♦" || card === "A♣"){
27-
return 11;
25+
const rank = card.slice(0, -1); // everything except the last character (suit)
26+
const validSuits = ["♠", "♥", "♦", "♣"];
27+
const suit = card.slice(-1);
28+
29+
if (!validSuits.includes(suit)) {
30+
throw new Error("Invalid card");
2831
}
29-
else if(card === "J♠" || card === "J♥" || card === "J♦" || card === "J♣" || card === "Q♠" || card === "Q♥" || card === "Q♦" || card === "Q♣" || card === "K♠" || card === "K♥" || card === "K♦" || card === "K♣"){
32+
33+
if (rank === "A") {
34+
return 11;
35+
} else if (rank === "J" || rank === "Q" || rank === "K") {
3036
return 10;
31-
}
32-
else if(card === "2♠" || card === "2♥" || card === "2♦" || card === "2♣"){
33-
return 2;
34-
}
35-
else if(card === "3♠" || card === "3♥" || card === "3♦" || card === "3♣"){
36-
return 3;
37-
}
38-
else {
37+
} else if (["2","3","4","5","6","7","8","9","10"].includes(rank)) {
38+
return Number(rank);
39+
} else {
3940
throw new Error("Invalid card");
4041
}
4142
}
@@ -74,11 +75,14 @@ assertEquals(getCardValue("2♠"), 2);
7475
assertEquals(getCardValue("3♥"), 3);
7576

7677
// What other valid card cases can you think of?
77-
function assertEqual(func, valid message){
78-
try{
79-
func();
80-
console.log("Valid card test passed ");
81-
}
78+
function assertEqual(func, message) {
79+
try {
80+
func();
81+
console.log("Valid card test passed: " + message);
82+
} catch (e) {
83+
console.error("Valid card test failed: " + message + " — " + e.message);
84+
}
85+
}
8286
// What other invalid card cases can you think of?
8387
function assertThrows(func, errorMessage) {
8488
try {
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
function getOrdinalNumber(num) {
2-
return "1st";
2+
const lastTwoDigits = num % 100;
3+
const lastDigit = num % 10;
4+
5+
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
6+
return `${num}th`;
7+
}
8+
9+
if (lastDigit === 1) {
10+
return `${num}st`;
11+
} else if (lastDigit === 2) {
12+
return `${num}nd`;
13+
} else if (lastDigit === 3) {
14+
return `${num}rd`;
15+
} else {
16+
return `${num}th`;
17+
}
318
}
419

5-
module.exports = getOrdinalNumber;
20+
module.exports = getOrdinalNumber;

0 commit comments

Comments
 (0)