diff --git a/week-3/debug/format-as-12-hours.js b/week-3/debug/format-as-12-hours.js index 56b83a5b..c4c14c97 100644 --- a/week-3/debug/format-as-12-hours.js +++ b/week-3/debug/format-as-12-hours.js @@ -1,6 +1,6 @@ function formatAs12HourClock(time) { if (Number(time.slice(0, 2)) > 12) { - return `${Number(time.slice(0, 2)) - 12}:00 pm`; + return `${Number(time.slice(0, 2)) - 12}:${time.slice(3, 5)} pm`; } return `${time} am`; } @@ -23,8 +23,18 @@ console.assert( targetOutput2 ); +const currentOutput3 = formatAs12HourClock("17:42"); +const targetOutput3 = "5:42 pm"; +console.assert( + currentOutput3 === targetOutput3, + "current output: %s, target output: %s", + currentOutput3, + targetOutput3 +); + // formatAs12HourClock currently has a 🐛 // a) Write an assertion to check the return value of formatAs12HourClock when it is called with an input "17:42" // b) Check the assertion output and explain what the bug is +// the function was designed to exclusively access the hour component // c) Now fix the bug and re-run all your assertions diff --git a/week-3/implement/get-angle-type.js b/week-3/implement/get-angle-type.js index 9dd3a210..b5abbde9 100644 --- a/week-3/implement/get-angle-type.js +++ b/week-3/implement/get-angle-type.js @@ -21,3 +21,18 @@ // Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" +function getAngleType(Angles) { + if (Angles == 90) { + return "Right angle"; + } else if (Angles < 90) { + return "Acute angle"; + } else if (Angles == 180) { + return "Straight angle"; + } else if (Angles > 180 && AngleS < 360) { + return "reflex angle"; + } else { + return "it's not angle"; + } + } + var AngleS = 350; + console.log(getAngleType(AngleS)); diff --git a/week-3/implement/get-card-value.js b/week-3/implement/get-card-value.js index 0dd74fbc..970100d3 100644 --- a/week-3/implement/get-card-value.js +++ b/week-3/implement/get-card-value.js @@ -29,3 +29,17 @@ // 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." +function getCardValue(cardValue) { + if (cardValue === "A♠") { + return 1; + } else if (cardValue >= 2 && cardValue <= 10) { + return Number(cardValue); + } else if (cardValue === "J" || cardValue === "Q" || cardValue === "K") { + return 10; + } else if (cardValue === "A") { + return 11; + } else { + return "Invalid card rank"; + } +} +console.log(getCardValue("A♠")); diff --git a/week-3/implement/is-proper-fraction.js b/week-3/implement/is-proper-fraction.js index 31da32b5..c825c706 100644 --- a/week-3/implement/is-proper-fraction.js +++ b/week-3/implement/is-proper-fraction.js @@ -33,3 +33,16 @@ // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. // These acceptance criteria cover a range of scenarios to ensure that the isProperFraction function handles both proper and improper fractions correctly and handles potential errors such as a zero denominator. +function isProperFraction(numerator, denominator) { + if (numerator >= denominator && denominator != 0) { + return "false"; + } else if (numerator < denominator) { + return "True"; + } else { + return "error"; + } +} +console.log(isProperFraction(5, 2)); +console.log(isProperFraction(3, 0)); +console.log(isProperFraction(-4, 7)); +console.log(isProperFraction(3, 3)); diff --git a/week-3/implement/is-valid-triangle.js b/week-3/implement/is-valid-triangle.js index 7b22836b..c768a66d 100644 --- a/week-3/implement/is-valid-triangle.js +++ b/week-3/implement/is-valid-triangle.js @@ -38,3 +38,16 @@ // Then it should return true because the input forms a valid triangle. // This specification outlines the behavior of the isValidTriangle function for different input scenarios, ensuring it properly checks for invalid side lengths and whether they form a valid triangle according to the Triangle Inequality Theorem. +function isValidTriangle(side1, side2, side3) { + if ( + side1 + side2 <= side3 || + side1 + side3 <= side2 || + (side2 + side3 <= side1 && side1 <= 0) || + side2 <= 0 || + side3 <= 0 + ) { + return "false"; + } else { + return "turn"; + } +} diff --git a/week-3/refactor/format-as-12-hours.js b/week-3/refactor/format-as-12-hours.js index 41603122..0951c904 100644 --- a/week-3/refactor/format-as-12-hours.js +++ b/week-3/refactor/format-as-12-hours.js @@ -4,3 +4,29 @@ // Store this expression in a variable and reference it twice in the function in the correct place // Explain why it makes more sense to store this expression in a variable +//after storing the expression in variable, there is no need to rewrite the expression +function formatAs12HourClock(time) { + const clockHourIn12 = Number(time.slice(0, 2)); + if (clockHourIn12 > 12) { + return `${clockHourIn12 - 12}:00 pm`; + } + return `${time} am`; +} + +const currentOutput = formatAs12HourClock("08:00"); +const targetOutput = "08:00 am"; +console.assert( + currentOutput === targetOutput, + "current output: %s, target output: %s", + currentOutput, + targetOutput +); + +const currentOutput2 = formatAs12HourClock("23:00"); +const targetOutput2 = "11:00 pm"; +console.assert( + currentOutput2 === targetOutput2, + "current output: %s, target output: %s", + currentOutput2, + targetOutput2 +); diff --git a/week-3/refactor/is-vowel.js b/week-3/refactor/is-vowel.js index db675d2b..0ede673d 100644 --- a/week-3/refactor/is-vowel.js +++ b/week-3/refactor/is-vowel.js @@ -3,12 +3,11 @@ function isVowel(letter) { letter === "a" || letter === "e" || letter === "i" || - letter === "i" || letter === "o" || letter === "u" ); } - +//letter i // here is an implementation of isVowel - this function checks if a letter is a vowel console.log("case: letter a...");