Skip to content

Commit 2c63e1a

Browse files
committed
Some changes due to review.
1 parent 351cb9e commit 2c63e1a

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@ function getAngleType(angle) {
1212
return "Right angle";
1313
}
1414
else if (angle < 90) {
15-
return "Acute angle"
15+
return "Acute angle";
1616
}
1717
else if (angle > 90 && angle < 180){
18-
return "Obtuse angle"
18+
return "Obtuse angle";
1919
}
2020
else if ( angle === 180){
21-
return "Straight angle"
21+
return "Straight angle";
2222
}
2323
else if (angle > 180 && angle < 360) {
24-
return "Reflex angle"
24+
return "Reflex angle";
25+
}
26+
else {
27+
return "invalid angle";
2528
}
2629

2730
// Run the tests, work out what Case 2 is testing, and implement the required code here.

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
1010
function getCardValue(card) {
11-
let rank = card.slice(0, card.length-1)
11+
let rank = card.slice(0, -1);
12+
let intPart;
13+
if (!isNaN(rank)){
14+
intPart = parseInt(rank);
15+
}
1216
if (rank === "A") {
1317
return 11;
1418
}
15-
else if ((parseInt(rank) >= 2 && parseInt(rank)) && parseInt(rank) < 11){
19+
else if (intPart >= 2 && intPart && intPart < 11){
1620
return parseInt(rank)
1721
}
18-
else if( rank === "J" || rank === "Q" || rank === "K") {
22+
else if(["J", "Q", "K"].includes(rank)) {
1923
return 10;
2024
}
2125
else{
22-
throw new Error("Invalid card rank.")
23-
}
24-
25-
26+
throw new Error("Invalid card rank.");
27+
}
2628
}
2729

2830
// The line below allows us to load the getCardValue function into tests in other files.
@@ -76,10 +78,9 @@ assertEquals(aceOfHeart, 11);
7678
// Given a card with an invalid rank (neither a number nor a recognized face card),
7779
// When the function is called with such a card,
7880
// Then it should throw an error indicating "Invalid card rank."
79-
80-
8181
try {
82-
assertEquals(getCardValue("W♥"), "Invalid card rank");
82+
getCardValue("W♥");
83+
console.log("❌ Test failed: no error thrown");
8384
} catch (error) {
84-
console.log(error.message);
85+
assertEquals(error.message, "Invalid card rank.");
8586
}

0 commit comments

Comments
 (0)