-
-
Notifications
You must be signed in to change notification settings - Fork 195
Glasgow | May-2025 | Salah Ahmed| Sprint-3 #634
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 45 commits
41faaac
fb392b3
52148a6
4d0497e
13220cd
396094b
f3b70e8
8ca4e8e
a9c9341
b1b2078
78e3a52
c75235c
39aad2d
0d2e786
ef3385f
f381483
49bcbfe
5774458
9226863
e8bdd72
03fd47d
61cdb3e
41d94fc
0f70f77
830b5e4
b500e15
e931299
315ab1a
aae7d84
2fd86de
c693e17
4330f25
d92d35c
c45f222
388622f
51997e1
88e292d
7829d7e
e924d5d
475029a
65bcde5
fef80b8
9549f29
97d365f
35c9171
5677d8b
ec1de20
11f25a5
a9d379c
d2b2de9
c571045
4f777e0
749afc7
5ff8087
dc7f375
2c6495f
508e086
c38f34c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
|
||
// Implement a function getAngleType | ||
// Build up your function case by case, writing tests as you go | ||
// The first test and case is written for you. The next case has a test, but no code. | ||
// Execute this script in your terminal | ||
// node 1-get-angle-type.js | ||
//node 1-get-angle-type.js | ||
// The assertion error will tell you what the expected output is | ||
// Write the code to pass the test | ||
// Then, write the next test! :) Go through this process until all the cases are implemented | ||
|
||
function getAngleType(angle) { | ||
if (angle === 90) return "Right angle"; | ||
if (angle === 90) return "Right angle"; | ||
if (angle > 0 && angle < 90) return "Acute angle"; | ||
if (angle > 90 && angle < 180) return "Obtuse angle"; | ||
if (angle === 180) return "Straight angle"; | ||
if (angle > 180 && angle < 360) return "Reflex angle"; | ||
// If the angle is not in any of the above categories, we can return a default value | ||
return "Unknown angle type"; | ||
avatarit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// read to the end, complete line 36, then pass your test here | ||
} | ||
|
||
|
@@ -42,15 +49,17 @@ assertEquals(acute, "Acute angle"); | |
// Case 3: Identify Obtuse Angles: | ||
// When the angle is greater than 90 degrees and less than 180 degrees, | ||
// Then the function should return "Obtuse angle" | ||
const obtuse = getAngleType(120); | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
const obtuse = getAngleType(120); | ||
assertEquals(obtuse,"Obtuse angle"); | ||
|
||
// Case 4: Identify Straight Angles: | ||
// When the angle is exactly 180 degrees, | ||
// Then the function should return "Straight angle" | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
const Straight = getAngleType(180); | ||
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. It's good practice to name your variables, functions and with a camelCase. Further reading: https://dev.to/hassanzohdy/best-practices-for-case-styles-camel-pascal-snake-and-kebab-case-in-node-and-javascript-55oi 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. I have changed the names of variables |
||
assertEquals(Straight,"Straight angle"); | ||
|
||
// Case 5: Identify Reflex Angles: | ||
// When the angle is greater than 180 degrees and less than 360 degrees, | ||
// Then the function should return "Reflex angle" | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
const Reflex = getAngleType(200); | ||
assertEquals(Reflex,"Reflex angle"); |
avatarit marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck | ||
|
||
// You will need to implement a function getCardValue | ||
// the function takes a single parameter, a string representing a playing card | ||
// the function should return the numerical value of the card | ||
|
@@ -8,20 +7,30 @@ | |
// 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; | ||
} | ||
if (!card || typeof card !== "string") return "Invalid card format"; | ||
//extracting the rank of the card | ||
const rank = card.slice(0, -1); | ||
|
||
//parseInt(rank) and Number(rank) are the same thing. parseInt() is a function that parses a string and returns an integer. If the first character in the string can't be converted into a number, then it returns NaN. Number() is a function that converts a string to a number. If the string can't be converted into a number, then it returns NaN. | ||
if (rank === "A") return 11; | ||
//For numerical cards, we return the number | ||
else if (Number(rank) >= 2 && Number(rank) <= 10) return Number(rank); | ||
//For face cards, we return 10 | ||
else if ( rank === "J" || rank=== "Q" || rank ==="K" ) return 10; | ||
//If the card is invalid, we throw an error | ||
else return("Invalid card rank."); | ||
} | ||
|
||
// You need to write assertions for your function to check it works in different cases | ||
// we're going to use this helper function to make our assertions easier to read | ||
// if the actual output matches the target output, the test will pass | ||
function assertEquals(actualOutput, targetOutput) { | ||
console.assert( | ||
actualOutput === targetOutput, | ||
`Expected ${actualOutput} to equal ${targetOutput}` | ||
); | ||
console.assert( | ||
actualOutput === targetOutput, | ||
`Expected ${actualOutput} to equal ${targetOutput}` | ||
); | ||
} | ||
// Acceptance criteria: | ||
|
||
// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A), | ||
// When the function getCardValue is called with this card string as input, | ||
// Then it should return the numerical card value | ||
|
@@ -33,19 +42,26 @@ assertEquals(aceofSpades, 11); | |
// 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♥"); | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
assertEquals(fiveofHearts,5); | ||
|
||
// 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. | ||
assertEquals(getCardValue("J♣"), 10); | ||
assertEquals(getCardValue("Q♦"), 10); | ||
assertEquals(getCardValue("K♠"), 10); | ||
|
||
// 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 aceofDiamonds = getCardValue("A♠"); | ||
assertEquals(aceofDiamonds, 11); | ||
|
||
// 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 Invalidcardrank = getCardValue("1♦"); | ||
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. Can you review this? Variables should start with a lowercase and follow camelCase. 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. Thanks! I have fixed them |
||
assertEquals(Invalidcardrank,"Invalid card rank."); |
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. This is a good set of tests. I would recommend adding a test for "Unknown angle type" since this is a part of your getAngleType function. |
avatarit marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
const isProperFraction = require("./2-is-proper-fraction"); | ||
|
||
|
||
test("should return true for a proper fraction", () => { | ||
expect(isProperFraction(2, 3)).toEqual(true); | ||
}); | ||
|
||
// Case 2: Identify Improper Fractions: | ||
test("should return false for an Improper fraction", () => { | ||
expect(isProperFraction(6, 3)).toEqual(false); | ||
}); | ||
|
||
test("should return false for a negative improper fraction", () => { | ||
avatarit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(isProperFraction(-3, -4)).toEqual(false); | ||
}); | ||
|
||
// Case 3: Identify Negative Fractions: | ||
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. This is actually an improper fraction (-5, -3). Can you see what the problem might be in your function and why this returns true when it should return false? |
||
test("should return true for a negative proper fraction", () => { | ||
avatarit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(isProperFraction(-5, -3)).toEqual(true); | ||
}); | ||
|
||
// Case 4: Identify Equal Numerator and Denominator: | ||
test("should return false for equal numerator and denominator", () => { | ||
expect(isProperFraction(5,5)).toEqual(false); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
|
||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
} | ||
if (!card || typeof card !== "string") return "Invalid card format"; | ||
//extracting the rank of the card | ||
const rank = card.slice(0, -1); | ||
|
||
//parseInt(rank) and Number(rank) are the same thing. parseInt() is a function that parses a string and returns an integer. If the first character in the string can't be converted into a number, then it returns NaN. Number() is a function that converts a string to a number. If the string can't be converted into a number, then it returns NaN. | ||
if (rank === "A") return 11; | ||
//For numerical cards, we return the number | ||
else if (Number(rank) >= 2 && Number(rank) <= 10) return Number(rank); | ||
//For face cards, we return 10 | ||
else if ( rank === "J" || rank=== "Q" || rank ==="K" ) return 10; | ||
//If the card is invalid, we throw an error | ||
else return("Invalid card rank."); | ||
} | ||
|
||
module.exports = getCardValue; |
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. Good set of tests here 👍 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,40 @@ | ||
const getCardValue = require("./3-get-card-value"); | ||
|
||
test("should return 11 for Ace of Spades", () => { | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
|
||
// Case 2: Handle Number Cards (2-10): | ||
|
||
|
||
test("should return the correct value for number cards (2-10)", () => { | ||
expect(getCardValue("2♦")).toEqual(2); | ||
expect(getCardValue("5♣")).toEqual(5); | ||
expect(getCardValue("10♥")).toEqual(10); | ||
}); | ||
|
||
// Case 3: Handle Face Cards (J, Q, K): | ||
|
||
|
||
test("should return 10 for face cards (J, Q, K)", () => { | ||
expect(getCardValue("J♠")).toEqual(10); | ||
expect(getCardValue("Q♦")).toEqual(10); | ||
expect(getCardValue("K♣")).toEqual(10); | ||
}); | ||
|
||
// Case 4: Handle Ace (A): | ||
// Case 5: Handle Invalid Cards: | ||
|
||
test("should return 11 for Ace", () => { | ||
expect(getCardValue("A♠")).toEqual(11); | ||
expect(getCardValue("A♣")).toEqual(11); | ||
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. Lines 28-30 all test the same thing. |
||
expect(getCardValue("A♦")).toEqual(11); | ||
}); | ||
|
||
// Case 5: Handle Invalid Cards: | ||
|
||
test("should throw an error for invalid cards", () => { | ||
expect(getCardValue("Z♦")).toEqual("Invalid card rank."); | ||
expect(getCardValue("15♥")).toEqual("Invalid card rank."); | ||
expect(getCardValue("X♣")).toEqual("Invalid card rank."); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
//return 5 | ||
|
||
return stringOfCharacters.split(findCharacter).length - 1; | ||
} | ||
|
||
module.exports = countChar; |
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.
Can you remove this file from your PR? It may have been added by mistake. Once your PR has been created, it's a good habit to review the files and ensure that only the required files are included! :)