+
+
+
+
\ No newline at end of file
diff --git a/Sprint-1/prep/percentage.html b/Sprint-1/prep/percentage.html
new file mode 100644
index 000000000..065781e07
--- /dev/null
+++ b/Sprint-1/prep/percentage.html
@@ -0,0 +1,136 @@
+
+
+
+
+
+ Percentage Exercise
+
+
+
+
Percentage Exercise
+
+
+
Convert Decimal to Percentage
+
enter a decimal number and click the button to see the percentage:
+
+
+
+
+
+
+
Calculate the area and perimeter
+
enter the width and height to calculate the area and perimeter
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Sprint-1/prep/simpleExampleOfEventlistener.html b/Sprint-1/prep/simpleExampleOfEventlistener.html
new file mode 100644
index 000000000..741df24d5
--- /dev/null
+++ b/Sprint-1/prep/simpleExampleOfEventlistener.html
@@ -0,0 +1,94 @@
+
+
+
+
+
+
+ Simple Example of Event Listener
+
+
+
+
+
Simple Example of Event Listener
+click the button to see the event listener in action:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js
index 95b6ebb7d..dc7572165 100644
--- a/Sprint-3/2-practice-tdd/count.js
+++ b/Sprint-3/2-practice-tdd/count.js
@@ -1,5 +1,16 @@
function countChar(stringOfCharacters, findCharacter) {
- return 5
+ let counter = 0 ;
+ for (let i=0 ;i< stringOfCharacters.length ; i++){
+ if (stringOfCharacters.charAt(i)==findCharacter){
+ counter ++;
+
+ }
+
+ }
+ return counter;
}
+console.log(countChar("aaa","a"));
+console.log(countChar("aaba","b"));
module.exports = countChar;
+
diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js
index 42baf4b4b..e0c90c778 100644
--- a/Sprint-3/2-practice-tdd/count.test.js
+++ b/Sprint-3/2-practice-tdd/count.test.js
@@ -17,8 +17,22 @@ test("should count multiple occurrences of a character", () => {
expect(count).toEqual(5);
});
+test("should count multiple occurrences of a character", () => {
+ const str = "aaaa";
+ const char = "a";
+ const count = countChar(str, char);
+ expect(count).toEqual(4);
+});
+
// Scenario: No Occurrences
// Given the input string str,
// 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 count multiple No occurrences of a character", () => {
+ const str = "aaaa";
+ const char = "b";
+ const count = countChar(str, char);
+ expect(count).toEqual(0);
+});
+
diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js
index f95d71db1..eba660e50 100644
--- a/Sprint-3/2-practice-tdd/get-ordinal-number.js
+++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js
@@ -1,5 +1,15 @@
function getOrdinalNumber(num) {
- return "1st";
+ const numberLastTwoDigits = num % 100;
+
+ if (numberLastTwoDigits === 11 || numberLastTwoDigits === 12 || numberLastTwoDigits === 13) {
+ return num + "th";
+ }
+
+ const numberLastDigit = num % 10;
+ if (numberLastDigit === 1) return num + "st";
+ if (numberLastDigit === 2) return num + "nd";
+ if (numberLastDigit === 3) return num + "rd";
+ return num + "th";
}
module.exports = getOrdinalNumber;
diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js
index dfe4b6091..c00dfe516 100644
--- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js
+++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js
@@ -1,13 +1,42 @@
const getOrdinalNumber = require("./get-ordinal-number");
-// In this week's prep, we started implementing getOrdinalNumber
-// continue testing and implementing getOrdinalNumber for additional cases
-// Write your tests using Jest - remember to run your tests often for continual feedback
+describe("getOrdinalNumber", () => {
+ test("returns 'st', 'nd', 'rd', 'th' for standard numbers", () => {
+ expect(getOrdinalNumber(1)).toBe("1st");
+ expect(getOrdinalNumber(2)).toBe("2nd");
+ expect(getOrdinalNumber(3)).toBe("3rd");
+ expect(getOrdinalNumber(4)).toBe("4th");
+ expect(getOrdinalNumber(10)).toBe("10th");
+ });
-// Case 1: Identify the ordinal number for 1
-// When the number is 1,
-// Then the function should return "1st"
+ test("handles numbers ending with 11, 12, 13 as special cases", () => {
+ expect(getOrdinalNumber(11)).toBe("11th");
+ expect(getOrdinalNumber(12)).toBe("12th");
+ expect(getOrdinalNumber(13)).toBe("13th");
+ expect(getOrdinalNumber(111)).toBe("111th");
+ expect(getOrdinalNumber(112)).toBe("112th");
+ expect(getOrdinalNumber(113)).toBe("113th");
+ });
-test("should return '1st' for 1", () => {
- expect(getOrdinalNumber(1)).toEqual("1st");
+ test("handles numbers ending with 1, 2, or 3 correctly beyond 100", () => {
+ expect(getOrdinalNumber(101)).toBe("101st");
+ expect(getOrdinalNumber(102)).toBe("102nd");
+ expect(getOrdinalNumber(103)).toBe("103rd");
+ expect(getOrdinalNumber(104)).toBe("104th");
+ expect(getOrdinalNumber(132)).toBe("132nd");
+ });
+
+ test("returns '0th' for zero", () => {
+ expect(getOrdinalNumber(0)).toBe("0th");
+ });
+
+ test("works with large numbers", () => {
+ expect(getOrdinalNumber(1001)).toBe("1001st");
+ expect(getOrdinalNumber(1012)).toBe("1012th");
+ });
+
+ test("handles negative numbers", () => {
+ expect(getOrdinalNumber(-1)).toBe("-1st");
+ expect(getOrdinalNumber(-11)).toBe("-11th");
+ });
});
diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js
index 3838c7b00..d18b1dba2 100644
--- a/Sprint-3/2-practice-tdd/repeat-str.js
+++ b/Sprint-3/2-practice-tdd/repeat-str.js
@@ -1,5 +1,10 @@
-function repeatStr() {
- return "hellohellohello";
+function repeat(str, count) {
+ if (count < 0) {
+ throw new Error("count must be non-negative");
+ }
+ return str.repeat(count);
}
-module.exports = repeatStr;
+module.exports = repeat;
+
+
diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js
index fc59d019e..a6a819181 100644
--- a/Sprint-3/2-practice-tdd/repeat-str.test.js
+++ b/Sprint-3/2-practice-tdd/repeat-str.test.js
@@ -20,13 +20,30 @@ test("should repeat the string count times", () => {
// Given a target string str and a count equal to 1,
// When the repeatStr function is called with these inputs,
// Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition.
+test("should repeat the string count times", () => {
+ const str = "hello";
+ const count = 1;
+ const repeatedStr = repeat(str, count);
+ expect(repeatedStr).toEqual("hello");
+});
// case: Handle Count of 0:
// Given a target string str and a count equal to 0,
// When the repeatStr function is called with these inputs,
// Then it should return an empty string, ensuring that a count of 0 results in an empty output.
+test("should repeat the string count times", () => {
+ const str = "hello";
+ const count = 0;
+ const repeatedStr = repeat(str, count);
+ expect(repeatedStr).toEqual("");
+});
// case: Negative Count:
// Given a target string str and a negative integer count,
// When the repeatStr function is called with these inputs,
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
+test("should throw an error when count is negative", () => {
+ const str = "hello";
+ const count = -1;
+ expect(() => repeatStr(str, count)).toThrow("count must be non-negative");
+});
diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js
new file mode 100644
index 000000000..ecd1d74b9
--- /dev/null
+++ b/Sprint-3/2-practice-tdd/repeat.js
@@ -0,0 +1,11 @@
+function repeat(str,count) {
+ if (count=== 0){
+ return ""
+ }
+ if(count<0){
+ return "invalid"
+ }
+ return str.repeat(count);
+}
+
+module.exports = repeat;