London | May-2026-itp | Vitalii Kmit | Sprint 3 | Implement and rewrite tests#1463
London | May-2026-itp | Vitalii Kmit | Sprint 3 | Implement and rewrite tests#1463Vitalii-code wants to merge 5 commits into
Conversation
illicitonion
left a comment
There was a problem hiding this comment.
This generally looks good, but I left a few comments to look at :) Thanks!
| // TODO: Implement this function | ||
| if (angle > 0 && angle < 90) { | ||
| return "Acute angle"; | ||
| } else if (angle == 90) { |
There was a problem hiding this comment.
Here you're using == but JavaScript also has a === operator. Do you know the difference? Why have you chosen to use == here? When would === make more sense?
This applies in many places in your PR - please take a look at them all!
| return "Right angle"; | ||
| } else if (angle > 90 && angle < 180) { | ||
| return "Obtuse angle"; | ||
| } else if (angle == 180) { |
|
|
||
| function getCardValue(card) { | ||
| // TODO: Implement this function | ||
| const lastChar = card.length - 1; |
There was a problem hiding this comment.
The name of this variable suggests it contains a character. But it actually contains an index of a character. Can you think of a name that could make this more clear?
| } | ||
|
|
||
| if (!(suit === "♠" || suit === "♥" || suit === "♦" || suit === "♣")) { | ||
| throw new Error("Invalid suit ", suit); |
There was a problem hiding this comment.
It's often useful to include in an error message what the invalid data was. Imagine you're are running a big long programme, and aren't sure exactly what data is being processed - the more context we can give in errors the better.
| const rank = card.slice(0, lastChar); | ||
| const suit = card.slice(lastChar); | ||
|
|
||
| if (rank === "10") { |
There was a problem hiding this comment.
This works, but I'm curious - why did you decide to handle 10 specially here?
What would happen if someone passed the string "10Q" to this function? What would you want to happen? What other edge cases may you want to test for in your tests?
There was a problem hiding this comment.
Well because "10♠" is three characters so I decided to write a special case for it, otherwise all the others combinations should be something like this "K♠" so only two characters. It's probably not the best way to handle this but it works 🤷
There was a problem hiding this comment.
It works for half of this ("Don't have to worry about 3-character strings after this line"), but it doesn't work for e.g. the "10Q" example. Can you talk through what you expect to happen if someone passes "10Q" and what your code actually does?
There was a problem hiding this comment.
Please revert the changes to this file, they're not relevant for this exercise.
|
Thank you for your suggestions. I had a go at fixing the problems mentioned. |
| const rank = card.slice(0, lastChar); | ||
| const suit = card.slice(lastChar); | ||
|
|
||
| if (rank === "10") { |
There was a problem hiding this comment.
It works for half of this ("Don't have to worry about 3-character strings after this line"), but it doesn't work for e.g. the "10Q" example. Can you talk through what you expect to happen if someone passes "10Q" and what your code actually does?
| if (rank == "A") { | ||
| return 11; | ||
| } else if (rank == "J" || rank == "Q" || rank == "K") { |
There was a problem hiding this comment.
Why the == rather than === here?
| } | ||
|
|
||
| if (!(suit === "♠" || suit === "♥" || suit === "♦" || suit === "♣")) { | ||
| throw new Error( |
There was a problem hiding this comment.
I don't think this works like you think it does. Can you update your tests to show that the error message is what you expect it to be?
| } else if (!isNaN(rank)) { | ||
| return Number(rank); | ||
| } else { | ||
| throw new Error("Invalid card"); |
There was a problem hiding this comment.
This also has the same "what was wrong?" problem
Learners, PR Template
Self checklist
Changelist
In this PR I worked on adding tests with plain javascript and then with jest