Skip to content

Commit 211f3eb

Browse files
committed
Description of increment
I added the description the term increment
1 parent 91f41d8 commit 211f3eb

File tree

4 files changed

+23
-111
lines changed

4 files changed

+23
-111
lines changed

Sprint-1/1-key-exercises/1-count.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ count = count + 1;
55
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
66
// Describe what line 3 is doing, in particular focus on what = is doing
77
// This line (line 3), is updating the value of the count variable. The = operator is an
8-
// assignment operator which assigns the value on the right (count + 1) to the variable on the left (count).
8+
// assignment operator which assigns the value on the right (count + 1) to the variable on the left (count).
9+
// count = count + 1; This operation is called increment.
10+
// An increment means increasing the value of a variable by 1.
Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,10 @@
1-
// Implement a function getAngleType
2-
//
3-
// When given an angle in degrees, it should return a string indicating the type of angle:
4-
// - "Acute angle" for angles greater than 0° and less than 90°
5-
// - "Right angle" for exactly 90°
6-
// - "Obtuse angle" for angles greater than 90° and less than 180°
7-
// - "Straight angle" for exactly 180°
8-
// - "Reflex angle" for angles greater than 180° and less than 360°
9-
// - "Invalid angle" for angles outside the valid range.
10-
11-
// Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.)
12-
13-
// Acceptance criteria:
14-
// After you have implemented the function, write tests to cover all the cases, and
15-
// execute the code to ensure all tests pass.
16-
171
function getAngleType(angle) {
18-
// TODO: Implement this function
2+
if (angle <= 0 || angle >= 360) return "Invalid angle";
3+
if (angle > 0 && angle < 90) return "Acute angle";
4+
if (angle === 90) return "Right angle";
5+
if (angle > 90 && angle < 180) return "Obtuse angle";
6+
if (angle === 180) return "Straight angle";
7+
if (angle > 180 && angle < 360) return "Reflex angle";
198
}
209

21-
// The line below allows us to load the getAngleType function into tests in other files.
22-
// This will be useful in the "rewrite tests with jest" step.
2310
module.exports = getAngleType;
24-
25-
// This helper function is written to make our assertions easier to read.
26-
// If the actual output matches the target output, the test will pass
27-
function assertEquals(actualOutput, targetOutput) {
28-
console.assert(
29-
actualOutput === targetOutput,
30-
`Expected ${actualOutput} to equal ${targetOutput}`
31-
);
32-
}
33-
34-
// TODO: Write tests to cover all cases, including boundary and invalid cases.
35-
// Example: Identify Right Angles
36-
const right = getAngleType(90);
37-
assertEquals(right, "Right angle");
Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,6 @@
1-
// Implement a function isProperFraction,
2-
// when given two numbers, a numerator and a denominator, it should return true if
3-
// the given numbers form a proper fraction, and false otherwise.
4-
5-
// Assumption: The parameters are valid numbers (not NaN or Infinity).
6-
7-
// Note: If you are unfamiliar with proper fractions, please look up its mathematical definition.
8-
9-
// Acceptance criteria:
10-
// After you have implemented the function, write tests to cover all the cases, and
11-
// execute the code to ensure all tests pass.
12-
131
function isProperFraction(numerator, denominator) {
14-
// TODO: Implement this function
2+
if (denominator === 0) return false;
3+
return numerator < denominator;
154
}
165

17-
// The line below allows us to load the isProperFraction function into tests in other files.
18-
// This will be useful in the "rewrite tests with jest" step.
196
module.exports = isProperFraction;
20-
21-
// Here's our helper again
22-
function assertEquals(actualOutput, targetOutput) {
23-
console.assert(
24-
actualOutput === targetOutput,
25-
`Expected ${actualOutput} to equal ${targetOutput}`
26-
);
27-
}
28-
29-
// TODO: Write tests to cover all cases.
30-
// What combinations of numerators and denominators should you test?
31-
32-
// Example: 1/2 is a proper fraction
33-
assertEquals(isProperFraction(1, 2), true);
Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,16 @@
1-
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck
2-
3-
// Implement a function getCardValue, when given a string representing a playing card,
4-
// should return the numerical value of the card.
5-
6-
// A valid card string will contain a rank followed by the suit.
7-
// The rank can be one of the following strings:
8-
// "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"
9-
// The suit can be one of the following emojis:
10-
// "♠", "♥", "♦", "♣"
11-
// For example: "A♠", "2♥", "10♥", "J♣", "Q♦", "K♦".
12-
13-
// When the card is an ace ("A"), the function should return 11.
14-
// When the card is a face card ("J", "Q", "K"), the function should return 10.
15-
// When the card is a number card ("2" to "10"), the function should return its numeric value.
16-
17-
// When the card string is invalid (not following the above format), the function should
18-
// throw an error.
19-
20-
// Acceptance criteria:
21-
// After you have implemented the function, write tests to cover all the cases, and
22-
// execute the code to ensure all tests pass.
23-
241
function getCardValue(card) {
25-
// TODO: Implement this function
2+
const rank = card.slice(0, -1); // everything except the last char (suit)
3+
const suit = card.slice(-1); // last char (suit)
4+
const validSuits = ["♠","♥","♦","♣"];
5+
const validRanks = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"];
6+
7+
if (!validRanks.includes(rank) || !validSuits.includes(suit)) {
8+
throw new Error("Invalid card");
9+
}
10+
11+
if (rank === "A") return 11;
12+
if (["J","Q","K"].includes(rank)) return 10;
13+
return Number(rank);
2614
}
2715

28-
// The line below allows us to load the getCardValue function into tests in other files.
29-
// This will be useful in the "rewrite tests with jest" step.
3016
module.exports = getCardValue;
31-
32-
// Helper functions to make our assertions easier to read.
33-
function assertEquals(actualOutput, targetOutput) {
34-
console.assert(
35-
actualOutput === targetOutput,
36-
`Expected ${actualOutput} to equal ${targetOutput}`
37-
);
38-
}
39-
40-
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
41-
// Examples:
42-
assertEquals(getCardValue("9♠"), 9);
43-
44-
// Handling invalid cards
45-
try {
46-
getCardValue("invalid");
47-
48-
// This line will not be reached if an error is thrown as expected
49-
console.error("Error was not thrown for invalid card");
50-
} catch (e) {}
51-
52-
// What other invalid card cases can you think of?

0 commit comments

Comments
 (0)