Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 15 additions & 9 deletions Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@
// Then, write the next test! :) Go through this process until all the cases are implemented

function getAngleType(angle) {
if (angle === 90) return "Right angle";
// read to the end, complete line 36, then pass your test here
if (angle === 90) return "Right angle";
if (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";
// 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) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}

// Acceptance criteria:
Expand All @@ -43,14 +47,16 @@ assertEquals(acute, "Acute angle");
// 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
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);
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(300);
assertEquals(reflex, "Reflex angle");
25 changes: 20 additions & 5 deletions Sprint-3/1-key-implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@
// complete the rest of the tests and cases
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
function isProperFractionFix(numerator, denominator) {
if (denominator === 0) return false;
return Math.abs(numerator) < Math.abs(denominator);
}

// function isProperFraction(numerator, denominator) {
// if (numerator < denominator) return true;
// else return false;



// }

// here's our helper again
function assertEquals(actualOutput, targetOutput) {
console.assert(
Expand Down Expand Up @@ -40,14 +49,20 @@ assertEquals(improperFraction, false);
// 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);
// ====> complete with your assertion
assertEquals(negativeFraction, true);

// 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);
// ====> complete with your assertion
assertEquals(equalFraction, false);

// Stretch:
// What other scenarios could you test for?
// What other scenarios could you test for? - we can text non-integers
const wtoNegativeFraction = isProperFractionFix(-3, -2);
assertEquals(equalFraction, false);




22 changes: 20 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 @@ -8,8 +8,13 @@
// 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) {
const rank = card.slice(0, -1);
if (rank === "A") return 11;
}
if (rank === "J" || rank === "Q" || rank === "K" || rank === "10") return 10;
if (rank >= "2" && rank <= "9") return parseInt(rank);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does your function return the value you expected from each of the following function calls?

getCardValue("29♠");
getCardValue("0x02♠");
getCardValue("2.1♠")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the function does not return this numeric. In all three cases, the function throws an "Invalid card rank" error.

throw new Error("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
Expand All @@ -33,19 +38,32 @@ 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, parseInt(rank));

// 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 fiveofCard = getCardValue("Q♥");
assertEquals(fiveofCard, 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 fiveofAce = getCardValue("A♥");
assertEquals(fiveofAce, 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 fiveofInvalid = getCardValue("Z♥");
assertEquals(fiveofInvalid, Error);







4 changes: 4 additions & 0 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
if (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";
// replace with your completed function from key-implement

}
Expand Down
12 changes: 12 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 @@ -10,15 +10,27 @@ test("should identify right angle (90°)", () => {
// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"
test("should identify acute angle (<90°)", () => {
expect(getAngleType(45)).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 (120°)", () => {
expect(getAngleType(120)).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 (270°)", () => {
expect(getAngleType(270)).toEqual("Reflex angle");
});
13 changes: 10 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,13 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
}
if (denominator === 0) return false;
return Math.abs(numerator) < Math.abs(denominator);
}
// function isProperFraction(numerator, denominator) {
// if (numerator < denominator) return true;
// else return false;
// // add your completed function from key-implement here
// }



module.exports = isProperFraction;
9 changes: 7 additions & 2 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ const isProperFraction = require("./2-is-proper-fraction");

test("should return true for a proper fraction", () => {
expect(isProperFraction(2, 3)).toEqual(true);
});
expect(isProperFraction(5, 2)).toEqual(false);
expect(isProperFraction(5, -2)).toEqual(false);
expect(isProperFraction(-5, 2)).toEqual(false);
expect(isProperFraction(-5, -2)).toEqual(false);
});


// Case 2: Identify Improper Fractions:

// Case 3: Identify Negative Fractions:

// Case 3: Identify Negative Fractions:
// Case 4: Identify Equal Numerator and Denominator:
14 changes: 11 additions & 3 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
function getCardValue(card) {

// replace with your code from key-implement
return 11;
}

function getCardValue(card) {
const rank = card.slice(0, -1);
if (rank === "A") return 11;
if (["J", "Q", "K", "10"].includes(rank)) return 10;
if (/^[2-9]$/.test(rank)) return Number(rank);
throw new Error("Invalid")
}


module.exports = getCardValue;
32 changes: 29 additions & 3 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
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("Handle Number Cards 2-10", () => {
const fiveOfHearts = getCardValue("5♥");
expect(fiveOfHearts).toEqual(5);
});

// Case 3: Handle Face Cards (J, Q, K):
test("Handle Face Cards J, Q, K", () => {
const handleFace = getCardValue("Q♥");
expect(handleFace).toEqual(10);
});

// Case 4: Handle Ace (A):
// Case 5: Handle Invalid Cards:
test("Handle Ace (A)", () => {
const handleAce = getCardValue("A♥");
expect(handleAce).toEqual(11);
});

// // Case 5: Handle Invalid Cards:
// test("Handle Ace (A)", () => {
// const handleAce = getCardValue("29♠");
// expect(handleAce).toEqual("Invalid");
// });

//Case 5: Handle Invalid Cards:
test("Handle Invalid Cards", () => {
expect(() => getCardValue("Z♥")).toThrow("Invalid");
expect(() => getCardValue("29♠")).toThrow("Invalid");
expect(() => getCardValue("2.1♠")).toThrow("Invalid");
});
10 changes: 8 additions & 2 deletions Sprint-3/3-mandatory-practice/implement/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
let count = 0;
for (let i = 0; i <stringOfCharacters.length;i++){
if(stringOfCharacters.charAt(i) === findCharacter ) {
count++
}
}
return count;
}

console.log (countChar('Maryna' , 'a'))
module.exports = countChar;
7 changes: 7 additions & 0 deletions Sprint-3/3-mandatory-practice/implement/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ test("should count multiple occurrences of a character", () => {
// And a character char that does not exist within the case-sensitive str,
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.

test("should return 0 when character is not in string", () => {
const str = "hello";
const char = "z";
const count = countChar(str, char);
expect(count).toEqual(0);
});
24 changes: 22 additions & 2 deletions Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
function getOrdinalNumber(num) {
return "1st";
function getOrdinalNumber(number) {

if (number < 1) return number;

let suffix = "th";
if (number % 100 !== 11 && number % 100 !== 12 && number % 100 !== 13) {
if (number % 10 === 1) suffix = "st";
else if (number % 10 === 2) suffix = "nd";
else if (number % 10 === 3) suffix = "rd";
}


return number + suffix;
}

console.log(getOrdinalNumber(1)); // "1st"
console.log(getOrdinalNumber(2)); // "2nd"
console.log(getOrdinalNumber(3)); // "3rd"
console.log(getOrdinalNumber(4)); // "4th"
console.log(getOrdinalNumber(11)); // "11th"
console.log(getOrdinalNumber(22)); // "22nd"
console.log(getOrdinalNumber(103)); // "103rd"


module.exports = getOrdinalNumber;
16 changes: 16 additions & 0 deletions Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ const getOrdinalNumber = require("./get-ordinal-number");
// When the number is 1,
// Then the function should return "1st"



test("getOrdinalNumber handles numbers ending with a right suffix", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
expect(getOrdinalNumber(23)).toEqual("23rd");
expect(getOrdinalNumber(53)).toEqual("53rd");
expect(getOrdinalNumber(103)).toEqual("103rd");
});

test("should return '2nd' for 2", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
});

test("should return '1st' for 1", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
});



11 changes: 8 additions & 3 deletions Sprint-3/3-mandatory-practice/implement/repeat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
function repeat() {
return "hellohellohello";
}
function repeat(word, count) {
if (count < 0) {
throw new Error("Count cannot be negative");
}
return word.repeat(count);
}

console.log (repeat ("hello"))

module.exports = repeat;
Loading