diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..39f38e3ba 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -1,6 +1,6 @@ -let count = 0; +let count = 0; //Variable "count" created and assigned value equal to 0. -count = count + 1; +count = count + 1; // Variable "count" assigned new value, equal old value + 1. // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..d5f44a71a 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,9 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. -let initials = ``; +let initials = firstName.charAt(0)+middleName.charAt(0)+lastName.charAt(0); +console.log(initials); + // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..7f00d14cf 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,12 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; + +const dir =filePath.slice(1,lastSlashIndex) ; +console.log(`****The dir part of ${filePath} is ${dir}`); +const lastIndexOfDot = filePath.lastIndexOf("."); +const ext = filePath.slice(lastIndexOfDot); +console.log(`**** The ext pert of ${filePath} is ${ext}`); + // https://www.google.com/search?q=slice+mdn \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..ccbe5bf2b 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -1,7 +1,14 @@ const minimum = 1; const maximum = 100; -const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +for ( let i = 0; i < 1000; i++){ + const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; + console.log(num); +} +// Math module used to generate random integer in range from 1 to 100, and assign it to variable "num" +// function ".random()" gives random float number fron 0 to 1 +// after this value multiplayed onto "(maximum - minimum + 1)" wich with give constants is equal to 100 +// function ".floor()" returns the largest integer less than or equal to a result of previous multiplication. // In this exercise, you will need to work out what num represents? // Try breaking down the expression and using documentation to explain what it means diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..e6b744a05 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,2 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +//This is just an instruction for the first activity - but it is just for human consumption +//We don't want the computer to run these 2 lines - how can we solve this problem? diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..457025bc8 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,6 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; + +console.log(age); \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..c441b2e77 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,6 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? -console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..c7f62a8a7 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,4 +1,4 @@ -const cardNumber = 4533787178994213; +const cardNumber = "4533787178994213"; const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..5945492ba 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const TwelveHourClockTime = "20:53"; +const TwentyFourHourClockTime = "08:53"; \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..bfbc9b029 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -12,11 +12,12 @@ console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below // a) How many function calls are there in this file? Write down all the lines where a function call is made - + // Three functions calls in lines 4,5,10 // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? - + // The error in line 5 // c) Identify all the lines that are variable reassignment statements - + //Reassignment in line 4,5 // d) Identify all the lines that are variable declarations - + //The variable declarations are in line 1,2,7,8 // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + //This code removes comas from prices before conversion to numbers. \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..ac0b492a5 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -1,4 +1,4 @@ -const movieLength = 8784; // length of movie in seconds +const movieLength = 50; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -12,14 +12,15 @@ console.log(result); // For the piece of code above, read the code and then answer the following questions // a) How many variable declarations are there in this program? - + // Thera are 6 variable declarations // b) How many function calls are there? - + // Thera is one function. // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators - + // The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? - + // It shows the number of full minutes in movie // e) What do you think the variable result represents? Can you think of a better name for this variable? - + // It shows the lengs of movie in format hours:minutes:seconds // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + // It will works \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..909f7cdfc 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,9 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 3. const penceStringWithoutTrailingP declared and assighed value - substring of penceString that's +// starts with 0 and end withouts last chracter +// 8. const paddedPenceNumberString declared and assighed value - If string penceStringWithoutTrailingP shorter than +// 3 characters, it add 0 to the starts. +// 14. const pence declared and assighed value - substring from variable paddedPenceNumberString ( last two characters) +// If string pence shorter than 2 characters, it add 0 to the end. diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feaf..260a33df7 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -11,8 +11,10 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? + //Pop up window with hello message appears. Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. What effect does calling the `prompt` function have? What is the return value of `prompt`? + //Pop up window with input field appears, after input function returns inputed string into Console. \ No newline at end of file diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56..44c44c6ed 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -5,12 +5,20 @@ In this activity, we'll explore some additional concepts that you'll encounter i Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? + // We got output like: ƒ log() { [native code] } Now enter just `console` in the Console, what output do you get back? + // We got: console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} Try also entering `typeof console` + //We got: 'object' Answer the following questions: -What does `console` store? +What does `console` store? + // Console store object, wich has methods to display different messages in console; What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? + //'.' - allows us to use functions and properties of console object. + // `log` and `assert` are these functions + // `console.log` to display console messages + // `console.assert`to write an error message to the console in case of assertion failed diff --git a/Sprint-3/1-key-implement/1-get-angle-type.js b/Sprint-3/1-key-implement/1-get-angle-type.js index 08d1f0cba..c2fa33231 100644 --- a/Sprint-3/1-key-implement/1-get-angle-type.js +++ b/Sprint-3/1-key-implement/1-get-angle-type.js @@ -9,7 +9,10 @@ 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 "Acute angle"; + if (angle >90 && angle < 180) return "Obtuse angle"; + if (angle === 180) return "Straight angle"; + if (angle >180 && angle < 360) return "Reflex angle"; } // we're going to use this helper function to make our assertions easier to read @@ -43,14 +46,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 \ No newline at end of file +const reflex = getAngleType(200); +assertEquals(reflex, "Reflex angle"); \ No newline at end of file diff --git a/Sprint-3/1-key-implement/2-is-proper-fraction.js b/Sprint-3/1-key-implement/2-is-proper-fraction.js index 91583e941..7570dd41e 100644 --- a/Sprint-3/1-key-implement/2-is-proper-fraction.js +++ b/Sprint-3/1-key-implement/2-is-proper-fraction.js @@ -8,8 +8,12 @@ // write one test at a time, and make it pass, build your solution up methodically function isProperFraction(numerator, denominator) { - if (numerator < denominator) return true; -} + if (numerator < denominator) { + return true; + } else if ( numerator >= denominator) { + return false; + } +} // here's our helper again function assertEquals(actualOutput, targetOutput) { @@ -40,6 +44,7 @@ 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); +assertEquals(negativeFraction,true ); // ====> complete with your assertion // Equal Numerator and Denominator check: @@ -47,6 +52,7 @@ const negativeFraction = isProperFraction(-4, 7); // 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: diff --git a/Sprint-3/1-key-implement/3-get-card-value.js b/Sprint-3/1-key-implement/3-get-card-value.js index aa1cc9f90..79957c77d 100644 --- a/Sprint-3/1-key-implement/3-get-card-value.js +++ b/Sprint-3/1-key-implement/3-get-card-value.js @@ -8,7 +8,22 @@ // 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; + if (card === "10"){ + rank = card; + } else { + rank = card.charAt(0); + } + + if (rank === "A") { + return 11; + } else if (Number(rank) >= 2 && Number(rank) <= 9) { + return Number(rank); + } else if (rank === "10" || rank === "J" || rank === "Q" || rank === "K") { + return 10; + } else { + throw new Error("Invalid card rank"); + } } // You need to write assertions for your function to check it works in different cases @@ -33,19 +48,30 @@ 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. +const faceCard = getCardValue("10"); +assertEquals(faceCard, 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 handleAce = getCardValue("A"); +assertEquals(handleAce, 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." +try { + const invalidCard = getCardValue("g"); + assertEquals(invalidCard, "Invalid card rank."); +} catch(error){ + console.log(error.message); +} + diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js index d61254bd7..830f5a476 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js @@ -1,16 +1,11 @@ function getAngleType(angle) { if (angle === 90) return "Right angle"; - // replace with your completed function from key-implement - + 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"; } - - - - - - - // Don't get bogged down in this detail // Jest uses CommonJS module syntax by default as it's quite old // We will upgrade our approach to ES6 modules in the next course module, so for now diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js index b62827b7c..17b156e38 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js @@ -7,18 +7,18 @@ test("should identify right angle (90°)", () => { // REPLACE the comments with the tests // make your test descriptions as clear and readable as possible -// 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(40)).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° and < 180°)", () => { + 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 (> 180° and < 360°)", () => { + expect(getAngleType(200)).toEqual("Reflex angle"); +}); diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js index 9836fe398..a11d8a038 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js @@ -1,6 +1,9 @@ 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 >= denominator) { + return false; + } } module.exports = isProperFraction; \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js index ff1cc8173..04df4f3b9 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js @@ -5,7 +5,16 @@ test("should return true for a proper fraction", () => { }); // Case 2: Identify Improper Fractions: +test("should return true 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(-2, 3)).toEqual(true); +}); // Case 4: Identify Equal Numerator and Denominator: +test("should return true for a equal fraction", () => { + expect(isProperFraction(3, 3)).toEqual(false); +}); diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js index 0d95d3736..1f1a44265 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js @@ -1,5 +1,18 @@ function getCardValue(card) { - // replace with your code from key-implement + let rank; + if (card === "10"){ + rank = card; + } else { + rank = card.charAt(0); + } + if (rank === "A") { return 11; + } else if (Number(rank) >= 2 && Number(rank) <= 9) { + return Number(rank); + } else if (rank === "10" || rank === "J" || rank === "Q" || rank === "K") { + return 10; + } else { + throw new Error("Invalid card rank"); + } } module.exports = getCardValue; \ No newline at end of file diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 03a8e2f34..810f292fe 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -3,9 +3,28 @@ const getCardValue = require("./3-get-card-value"); test("should return 11 for Ace of Spades", () => { const aceofSpades = getCardValue("A♠"); expect(aceofSpades).toEqual(11); - }); +}); // Case 2: Handle Number Cards (2-10): +test("should return rank for Number Cards (2-10)", () => { + const numberCards = getCardValue("7♠"); + expect(numberCards).toEqual(7); +}); + // Case 3: Handle Face Cards (J, Q, K): +test("should return 10 Face Cards (J, Q, K)", () => { + const faceCards = getCardValue("J"); + expect(faceCards).toEqual(10); +}); + // Case 4: Handle Ace (A): +test("should return 11 for Ace (A)", () => { + const aceCard = getCardValue("A"); + expect(aceCard).toEqual(11); +}); + // Case 5: Handle Invalid Cards: +test("should return error for invalid Cards", () => { + const numberCards = getCardValue("Z"); + expect(numberCards).toEqual("Invalid card rank."); +}); \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/count.js b/Sprint-3/3-mandatory-practice/implement/count.js index fce249650..1011fdb31 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.js +++ b/Sprint-3/3-mandatory-practice/implement/count.js @@ -1,5 +1,9 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + for (char in stringOfCharacters) { + if (char === findCharacter) count++; + } + return count; } module.exports = countChar; \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/count.test.js b/Sprint-3/3-mandatory-practice/implement/count.test.js index 42baf4b4b..556ff9d05 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.test.js +++ b/Sprint-3/3-mandatory-practice/implement/count.test.js @@ -22,3 +22,9 @@ 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 count multiple occurrences of a character", () => { + const str = "aaaaa"; + const char = "b"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js index 24f528b0d..e8ff4654f 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js @@ -1,5 +1,5 @@ function getOrdinalNumber(num) { - return "1st"; + return "${num}st"; } module.exports = getOrdinalNumber; \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index 6d55dfbb4..380adce6d 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -10,4 +10,4 @@ const getOrdinalNumber = require("./get-ordinal-number"); test("should return '1st' for 1", () => { expect(getOrdinalNumber(1)).toEqual("1st"); - }); +}); diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index 621f9bd35..224bb1a62 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -1,5 +1,9 @@ -function repeat() { - return "hellohellohello"; +function repeat(str, num) { + if (num == 0 ) { + return ''; + } else { + return str.repeat(num); + } } module.exports = repeat; \ No newline at end of file diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.test.js b/Sprint-3/3-mandatory-practice/implement/repeat.test.js index 8a4ab42ef..d2eb687c3 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.test.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.test.js @@ -14,19 +14,37 @@ test("should repeat the string count times", () => { const count = 3; const repeatedStr = repeat(str, count); expect(repeatedStr).toEqual("hellohellohello"); - }); +}); // case: handle Count of 1: // Given a target string str and a count equal to 1, // When the repeat 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 repeat 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 repeat 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 repeat the string count times", () => { + const str = "hello"; + const count = -1; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual(""); +}); \ No newline at end of file diff --git a/Sprint-3/4-stretch-investigate/password-validator.js b/Sprint-3/4-stretch-investigate/password-validator.js index b55d527db..964cbfa0e 100644 --- a/Sprint-3/4-stretch-investigate/password-validator.js +++ b/Sprint-3/4-stretch-investigate/password-validator.js @@ -1,6 +1,17 @@ function passwordValidator(password) { - return password.length < 5 ? false : true + if ( password.length < 5 ) { + return false; + } else if (password.search[/A-Z/i] < 0){ + return false; + } else if (password.search[/a-z/i] < 0){ + return false; + } else if (password.search[/0-9/] < 0 ){ + return false; + } else if (password.search[/!@#$%&*_?-/] < 0 ){ + return false; + } else { + return true; + } } - module.exports = passwordValidator; \ No newline at end of file diff --git a/Sprint-3/4-stretch-investigate/password-validator.test.js b/Sprint-3/4-stretch-investigate/password-validator.test.js index 8fa3089d6..5a712c4be 100644 --- a/Sprint-3/4-stretch-investigate/password-validator.test.js +++ b/Sprint-3/4-stretch-investigate/password-validator.test.js @@ -14,13 +14,30 @@ To be valid, a password must: You must breakdown this problem in order to solve it. Find one test case first and get that working */ -const isValidPassword = require("./password-validator"); +//const isValidPassword = require("./password-validator"); + + +function passwordValidator(password) { + if ( password.length < 5 ) { + return false; + } else if (password.search[/A-Z/i] < 0){ + return false; + } else if (password.search[/a-z/i] < 0){ + return false; + } else if (password.search[/0-9/] < 0 ){ + return false; + } else if (password.search[/!@#$%&*_?-/] < 0){ + return false; + } else { + return true; + } +} + test("password has at least 5 characters", () => { // Arrange const password = "12345"; // Act const result = isValidPassword(password); // Assert - expect(result).toEqual(true); -} -); \ No newline at end of file + expect(result).toEqual(false); +}); \ No newline at end of file