Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
7ce428b
put answer in comment
sarawone Feb 20, 2025
6442b27
getting dir and ext part from filepath
sarawone Feb 20, 2025
b31a592
breaking down the expression in step by step
sarawone Feb 21, 2025
8f67390
fixing error
sarawone Feb 21, 2025
abbe390
checking error and write the reason of the error.
sarawone Feb 21, 2025
03caef7
interpret and adding answers
sarawone Feb 21, 2025
c8d6e99
adding answers
sarawone Feb 21, 2025
da12dc5
finding error and explain
sarawone Feb 21, 2025
713cbf9
read and answer the questions
sarawone Feb 21, 2025
2b9bd4e
adding answers
sarawone Feb 22, 2025
73fec8d
adding answer
sarawone Feb 22, 2025
b352caf
adding code
sarawone Feb 22, 2025
6a87825
adding answers
sarawone Feb 22, 2025
aa2898b
adding answer
sarawone Feb 22, 2025
ccd7540
implement getCardValue function
sarawone Feb 24, 2025
9230d74
adding test function
sarawone Feb 24, 2025
b7a5527
adding function & jest statement
sarawone Feb 25, 2025
489ba23
restore Sprint1 to original
sarawone Mar 14, 2025
e55312c
restore sprint2 to original
sarawone Mar 14, 2025
0f67671
changing to original version
sarawone Mar 15, 2025
9e4d56b
changing to original version
sarawone Mar 15, 2025
11b6519
changing to original version
sarawone Mar 15, 2025
7ea8f44
changing to original version
sarawone Mar 15, 2025
b1f54f7
changing to original version
sarawone Mar 15, 2025
91e9e28
changing to original version
sarawone Mar 15, 2025
f05fc9a
changing to original version
sarawone Mar 15, 2025
d6fea99
changing to original version
sarawone Mar 15, 2025
67f6a60
changing to original version
sarawone Mar 15, 2025
d07cfb0
changing to original version
sarawone Mar 15, 2025
c784ca5
changing to original version
sarawone Mar 15, 2025
da915e1
changing to original version
sarawone Mar 15, 2025
577b9e6
changing to original version
sarawone Mar 15, 2025
67e1651
changing to original version
sarawone Mar 15, 2025
0c3f7af
Merge branch 'coursework/sprint-3' of https://github.com/sarawone/Mod…
sarawone Mar 15, 2025
41fc8bd
changing to original version
sarawone Mar 15, 2025
f5a5ee2
changing to original version
sarawone Mar 15, 2025
4893386
removing negative and modify function
sarawone Mar 17, 2025
541ddf2
changing the variable name
sarawone Mar 17, 2025
489ad20
modify the code
sarawone Mar 17, 2025
618ab0b
adding extra test
sarawone Mar 17, 2025
26fd07c
modify the function
sarawone Mar 17, 2025
75240a8
adding the test cases
sarawone Mar 17, 2025
aba23f6
testing with other cases
sarawone Mar 17, 2025
81cb2c5
adding throw in function
sarawone Mar 17, 2025
a12d680
adding test for throw
sarawone Mar 17, 2025
f16df6e
assign local variable by putting let
sarawone Mar 18, 2025
ea3e114
modify the function
sarawone Mar 18, 2025
b4066a2
changing variable name to ranks
sarawone Mar 18, 2025
648adf7
changing the error message
sarawone Mar 18, 2025
da614be
modify function
sarawone Mar 19, 2025
8a90ce6
adding test cases
sarawone Mar 19, 2025
65ad614
modify the function
sarawone Mar 19, 2025
a8c26e6
adding test cases and modify
sarawone Mar 19, 2025
9ed5a3e
adding test cases
sarawone Mar 19, 2025
9fba579
test cases added
sarawone Mar 19, 2025
0620564
modify the code
sarawone Mar 19, 2025
f00ef51
modify the code
sarawone Mar 19, 2025
42d22c1
modify to return number
sarawone Mar 19, 2025
8bc74aa
change variable name
sarawone Mar 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,32 @@
// 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";
}
else if (angle<90)
{
return "Acute angle";
}
else if (angle >90 && angle<180)
{
return "Obtuse angle";
}
else if (angle === 180)
{
return "Straight angle";
}
else if (angle >180 && angle<360)
{
return "Reflex angle";
}
// read to the end, complete line 36, then pass your test here

}



// 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) {
Expand All @@ -32,25 +54,41 @@ function assertEquals(actualOutput, targetOutput) {
// Then the function should return "Right angle"
const right = getAngleType(90);
assertEquals(right, "Right angle");
console.log(`The result is ${right}`);

// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"
const acute = getAngleType(45);
assertEquals(acute, "Acute angle");
//const acute = getAngleType(45);
//assertEquals(acute, "Acute angle");

const acute = getAngleType(80);
assertEquals (acute,"Acute angle");
console.log(`The result is ${acute}`);

// 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);
// 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");
console.log (`The result is ${obtuse}`);

// 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);
assertEquals(straight,"Straight angle");
console.log (`The result is ${straight}`);

// 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
// ====> write your test here, and then add a line to pass the test in the function above

const reflex = getAngleType(190);
assertEquals(reflex,"Reflex angle");
console.log(`The result is ${reflex}`);
35 changes: 34 additions & 1 deletion Sprint-3/1-key-implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
let num1 = Math.abs(numerator);
let num2 = Math.abs (denominator);
if (num1 < num2)
{
return true;
}
// else if (numerator<0 && denominator<0)
// {
// return true;
// }
else
{
return false;
}

}

// here's our helper again
Expand All @@ -35,19 +49,38 @@ assertEquals(properFraction, true);
const improperFraction = isProperFraction(5, 2);
assertEquals(improperFraction, false);

const improperFraction1 = isProperFraction(-5, -2);
assertEquals(improperFraction1, false);


const improperFraction2 = isProperFraction(-5, 2);
assertEquals(improperFraction2, false);

// Negative Fraction check:
// Input: numerator = -4, denominator = 7
// target output: true
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
const negativeFraction = isProperFraction(-4, 7);
assertEquals(negativeFraction,true);
// ====> complete with your assertion

// Equal Numerator and Denominator check:
// Input: numerator = 3, denominator = 3
// target output: false
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
const equalFraction = isProperFraction(3, 3);
assertEquals(equalFraction,false);
// ====> complete with your assertion

// Stretch:
// What other scenarios could you test for?

// both Numerator and denominator are negative
//Input : numerator = -3 , denominator = -4
// target out : true
// Explanation : if both numerator and denominator are negative, it will be equal to positive fraction
const negative = isProperFraction(-3,-4);
assertEquals(negative,true);
const negative1 = isProperFraction(-5,-4);
assertEquals(negative1,false);

69 changes: 67 additions & 2 deletions Sprint-3/1-key-implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,46 @@
// complete the rest of the tests and cases
// 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;

let rank = card.slice(0,-1); // drop one last letter from string

const faceCards = ["J","Q","K"]; // array for J,Q,K
const numberCards = ["2","3","4","5","6","7","8","9",]; // array for 2-9 card

if (rank === "A") // if the input is A return 11
{
return 11;
}
else if (card === "Ace") // if the input is Ace return 11
{
return 11;
}

else if (rank.length ==1 && faceCards.includes(rank) ) // input length is 1 and input is in rank 1 return 10;
{
return 10;
}

else if (rank === "10") // if input is 10 return 10;
{
return 10;
}


else if ( numberCards.includes(rank)=== true ) // if the input is within 2-9
{

return Number (rank);
}
else

{
return `The card is invalid`;
}


}

// You need to write assertions for your function to check it works in different cases
Expand All @@ -27,25 +65,52 @@ function assertEquals(actualOutput, targetOutput) {
// Then it should return the numerical card value
const aceofSpades = getCardValue("A♠");
assertEquals(aceofSpades, 11);
console.log(`A is equal to ${aceofSpades}`);

// Handle Number Cards (2-10):
// Given a card with a rank between "2" and "9",
// 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♥");
assertEquals(fiveofHearts,5);
console.log(`The result is ${fiveofHearts}`);

const twofHearts = getCardValue("2♥");
assertEquals(twofHearts,2);
console.log(`The result is ${twofHearts}`);
// ====> write your test here, and then add a line to pass the test in the function above

// 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.
const jack = getCardValue("J♥");
assertEquals(jack,10);
console.log(`J is equal to ${jack}`);

const tenHeart = getCardValue("10♥");
assertEquals(tenHeart,10);
console.log(`The result is ${tenHeart}`);
// 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 Ace = getCardValue("Ace");
assertEquals(Ace,11);
console.log(`Ace is ${Ace}`);
// 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 invalidNumber = getCardValue("15♠");
console.log("15 space is",`${invalidNumber}`);

const invalidNumber1 = getCardValue("0♠");
console.log(`${invalidNumber1}`);

const invalidNumber2 = getCardValue("B♠");
console.log(`${invalidNumber2}`);

const invalidNumber3 = getCardValue("123♠");
console.log(`${invalidNumber3}`);
22 changes: 20 additions & 2 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
// replace with your completed function from key-implement
if (angle === 90)
{
return "Right angle";
}
else if (angle<90)
{
return "Acute angle";
}
else if (angle >90 && angle<180)
{
return "Obtuse angle";
}
else if (angle === 180)
{
return "Straight angle";
}
else if (angle >180 && angle<360)
{
return "Reflex angle";
}

}

Expand Down
15 changes: 15 additions & 0 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,29 @@ test("should identify right angle (90°)", () => {
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"

test ("Should identify Acute Angle < 90", () => {
expect(getAngleType(80)).toEqual("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"
test ("Should identify Obtuse Angle > 90 && <180", () => {
expect(getAngleType(160)).toEqual("Obtuse Angle");
});

// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"
test ("Should identify Straight Angle=180", () => {
expect(getAngleType(180)).toEqual("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"

test ("Should identify Reflex Angle >180 and <360", () => {
expect(getAngleType(280)).toEqual("Reflex Angle");
});
17 changes: 14 additions & 3 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
}
if (numerator < denominator)
{
return true;
}
else if (numerator<0 && denominator<0)
{
return true;
}
else
{
return false;
}

}

module.exports = isProperFraction;
11 changes: 11 additions & 0 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ test("should return true for a proper fraction", () => {
});

// Case 2: Identify Improper Fractions:
test ("Should return false for a Improper Fraction", () =>{
expect(isProperFraction(5,3).toEqual(false));
});

// Case 3: Identify Negative Fractions:

test ("Should return true for a negative fraction", ()=>{
expect(isProperFraction(-1,2).toEqual(true));
});

// Case 4: Identify Equal Numerator and Denominator:

test ("Should return false for a equal case", ()=>{
expect(isProperFraction(2,2).toEqual(false));
});
43 changes: 41 additions & 2 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
function getCardValue(card) {
// replace with your code from key-implement
return 11;


let cards = card.slice(0,-1); // drop one last letter from string

const rank1= ["J","Q","K"];

if (cards === "A") // if the input is A return 11
{
return 11;
}
else if (card == "Ace") // if the input is Ace return 11
{
return 11;
}

else if (cards.length ==1 && rank1.includes(cards) ) // input length is 1 and input is in rank 1 return 10;
{
return 10;
}

else if (cards === "10") // if input is 10 return 10;
{
return 10;
}


else if (cards.length ==1 && rank1.includes(cards)=== false) // if input length is 1 & not include in rank1
{
value = Number(cards); // convert the input into number and return the value
return value;
}

else if (cards.length ==2 && cards != "10") // if input length is 2 and not equal to 10 return invalid
{
return `The card is invalid`;
}





}
module.exports = getCardValue;
Loading