From 05330b8b6125d1fada986aff4aa7c3497666b024 Mon Sep 17 00:00:00 2001 From: areebsattar Date: Sat, 18 Nov 2023 15:09:23 +0000 Subject: [PATCH 1/6] Debug complete --- week-3/debug/format-as-12-hours.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/week-3/debug/format-as-12-hours.js b/week-3/debug/format-as-12-hours.js index 56b83a5b..52cfd52d 100644 --- a/week-3/debug/format-as-12-hours.js +++ b/week-3/debug/format-as-12-hours.js @@ -1,6 +1,10 @@ function formatAs12HourClock(time) { if (Number(time.slice(0, 2)) > 12) { - return `${Number(time.slice(0, 2)) - 12}:00 pm`; + let timeFormat = (Number(time.slice(0, 2)) - 12) + if (timeFormat <10 ) + return `0${timeFormat}:${time.slice(3, 5)} pm`; + else + return`${timeFormat}:${time.slice(3, 5)} pm`; } return `${time} am`; } @@ -23,8 +27,17 @@ console.assert( targetOutput2 ); +const currentOutput1 = formatAs12HourClock("17:42"); +const targetOutput1 = "05:42 pm" +console.assert( + currentOutput1 === targetOutput1, + `current output: %s, target output: %s`, currentOutput1, targetOutput1 +) + // 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 +// Ans. The problem is that the hours are being calculated fine but minutes are not being considered as we don't have a calculation for minutes // c) Now fix the bug and re-run all your assertions +// Ans. Replaced 00 in line 3 with ${time.slice(3,5)} to return the minutes part back, From 5102fc4de84d5d2464cc3c472cb69f5e2b7ca853 Mon Sep 17 00:00:00 2001 From: areebsattar Date: Sat, 18 Nov 2023 15:14:54 +0000 Subject: [PATCH 2/6] updated answer --- week-3/debug/format-as-12-hours.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/week-3/debug/format-as-12-hours.js b/week-3/debug/format-as-12-hours.js index 52cfd52d..cad6e1c2 100644 --- a/week-3/debug/format-as-12-hours.js +++ b/week-3/debug/format-as-12-hours.js @@ -40,4 +40,5 @@ console.assert( // b) Check the assertion output and explain what the bug is // Ans. The problem is that the hours are being calculated fine but minutes are not being considered as we don't have a calculation for minutes // c) Now fix the bug and re-run all your assertions -// Ans. Replaced 00 in line 3 with ${time.slice(3,5)} to return the minutes part back, +// Ans. Replaced 00 in line 3 with ${time.slice(3,5)} to return the minutes part back, and added another if statement to get the desired result +// from line 3 to line 8. From fe54403f0b8cc6e6c115b258be7577f8aa6e2163 Mon Sep 17 00:00:00 2001 From: areebsattar Date: Sun, 19 Nov 2023 22:32:10 +0000 Subject: [PATCH 3/6] Completed implement --- week-3/implement/get-angle-type.js | 23 ++++++++++++++++++ week-3/implement/get-card-value.js | 33 ++++++++++++++++++++++++++ week-3/implement/is-proper-fraction.js | 32 +++++++++++++++++++++++++ week-3/implement/is-valid-triangle.js | 14 +++++++++++ 4 files changed, 102 insertions(+) diff --git a/week-3/implement/get-angle-type.js b/week-3/implement/get-angle-type.js index 9dd3a210..4166d2ca 100644 --- a/week-3/implement/get-angle-type.js +++ b/week-3/implement/get-angle-type.js @@ -21,3 +21,26 @@ // 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(angle){ + if (angle===90){ + return "Right Angle" + } + else if (angle<90){ + return "Acute Angle" + } + else if (angle>90 && angle<180){ + return "Obtuse Angle" + } + else if (angle===180){ + return "Straight Angle" + } + else if (angle>180 && angle<360){ + return "Reflex Angle" + } + else + return "Angle cannot be greater than 360 or less than 0" +} + +console.log (getAngleType(90)); \ No newline at end of file diff --git a/week-3/implement/get-card-value.js b/week-3/implement/get-card-value.js index 0dd74fbc..ae6c2454 100644 --- a/week-3/implement/get-card-value.js +++ b/week-3/implement/get-card-value.js @@ -29,3 +29,36 @@ // 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(str) { + if (str === "A") { + return 11; + } else if (str === "J" || str === "Q" || str === "K") { + return 10; + } else if (str > 1 && str < 11) { + return +str; + } else return "Invalid card rank"; +} +// console.log( typeof getCardValue("2")); + +const currentOutput = getCardValue("A"); //Change the value here to check against different assertions +const targetOutput = 2; +const targetOutput1 = 5; +const targetOutput2 = 10; // This will be true for "10", "J", "K" and "Q" +const targetOutput3 = 11; +console.assert( + currentOutput === targetOutput, + `current output: ${currentOutput}, target output: ${targetOutput} ` +); +console.assert( + currentOutput === targetOutput1, + `current output: ${currentOutput}, target output: ${targetOutput1} ` +); +console.assert( + currentOutput === targetOutput2, + `current output: ${currentOutput}, target output: ${targetOutput2} ` +); +console.assert( + currentOutput === targetOutput3, + `current output: ${currentOutput}, target output: ${targetOutput3} ` +); diff --git a/week-3/implement/is-proper-fraction.js b/week-3/implement/is-proper-fraction.js index 31da32b5..547780dc 100644 --- a/week-3/implement/is-proper-fraction.js +++ b/week-3/implement/is-proper-fraction.js @@ -33,3 +33,35 @@ // 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 (a,b){ + if (ab){ + return false; + } + else if (b=0){ + return ; + } + else if (a<0){ + return true; + } + else if (a===b){ + return false; + } +} +const currentOutput = isProperFraction(8,0); //Change the values here to check against different assertions +const targetOutput = true; +const targetOutput1 = false; +console.assert( + currentOutput === targetOutput, + `This Assertion is fails when it's not a proper fraction + current output: ${currentOutput}, target output: ${targetOutput} ` +); +console.assert( + currentOutput === targetOutput1, + `This Assertion is fails when it's a proper fraction + current output: ${currentOutput}, target output: ${targetOutput1} ` +); + diff --git a/week-3/implement/is-valid-triangle.js b/week-3/implement/is-valid-triangle.js index 7b22836b..a6755ba9 100644 --- a/week-3/implement/is-valid-triangle.js +++ b/week-3/implement/is-valid-triangle.js @@ -38,3 +38,17 @@ // 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(a,b,c){ + if (a+b<=c || a+c<=b || b+c<=a){ + return false; + } + else if (a<=0 || b<=0 || c<=0){ + return false; + } + else if(a+b>c && a+c>b && b+c>a){ + return true; + } +} + +console.log(isValidTriangle(3,3,3)); \ No newline at end of file From d6ba89ac03d4e7aa17a59db35d223117a5b70394 Mon Sep 17 00:00:00 2001 From: areebsattar Date: Sun, 19 Nov 2023 22:56:35 +0000 Subject: [PATCH 4/6] Completed Refactor and improved implement --- week-3/implement/get-card-value.js | 30 ++++++++++++++------- week-3/implement/is-proper-fraction.js | 17 +++++++----- week-3/refactor/format-as-12-hours.js | 37 ++++++++++++++++++++++++++ week-3/refactor/is-vowel.js | 13 +++++++-- 4 files changed, 78 insertions(+), 19 deletions(-) diff --git a/week-3/implement/get-card-value.js b/week-3/implement/get-card-value.js index ae6c2454..c7ba2250 100644 --- a/week-3/implement/get-card-value.js +++ b/week-3/implement/get-card-value.js @@ -41,24 +41,34 @@ function getCardValue(str) { } // console.log( typeof getCardValue("2")); -const currentOutput = getCardValue("A"); //Change the value here to check against different assertions +console.log("Checking result for 2"); +const currentOutput = getCardValue("2"); const targetOutput = 2; -const targetOutput1 = 5; -const targetOutput2 = 10; // This will be true for "10", "J", "K" and "Q" -const targetOutput3 = 11; console.assert( currentOutput === targetOutput, `current output: ${currentOutput}, target output: ${targetOutput} ` ); + +console.log("Checking result for 5"); +const currentOutput1 = getCardValue("5"); +const targetOutput1 = 5; console.assert( - currentOutput === targetOutput1, - `current output: ${currentOutput}, target output: ${targetOutput1} ` + currentOutput1 === targetOutput1, + `current output: ${currentOutput1}, target output: ${targetOutput1} ` ); + +console.log("Checking result for K"); +const currentOutput2 = getCardValue("K"); +const targetOutput2 = 10; // This will be true for "10", "J", "K" and "Q" console.assert( - currentOutput === targetOutput2, - `current output: ${currentOutput}, target output: ${targetOutput2} ` + currentOutput2 === targetOutput2, + `current output: ${currentOutput2}, target output: ${targetOutput2} ` ); + +console.log("Checking result for A"); +const currentOutput3 = getCardValue("A"); +const targetOutput3 = 11; console.assert( - currentOutput === targetOutput3, - `current output: ${currentOutput}, target output: ${targetOutput3} ` + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3} ` ); diff --git a/week-3/implement/is-proper-fraction.js b/week-3/implement/is-proper-fraction.js index 547780dc..6851292e 100644 --- a/week-3/implement/is-proper-fraction.js +++ b/week-3/implement/is-proper-fraction.js @@ -51,17 +51,20 @@ function isProperFraction (a,b){ return false; } } -const currentOutput = isProperFraction(8,0); //Change the values here to check against different assertions + +console.log("This Assertion is fails when it's not a proper fraction"); +const currentOutput = isProperFraction(8,9); const targetOutput = true; -const targetOutput1 = false; console.assert( currentOutput === targetOutput, - `This Assertion is fails when it's not a proper fraction - current output: ${currentOutput}, target output: ${targetOutput} ` + `current output: ${currentOutput}, target output: ${targetOutput} ` ); + +console.log("This Assertion is fails when it's a proper fraction"); +const currentOutput1 = isProperFraction(8, 4); +const targetOutput1 = false; console.assert( - currentOutput === targetOutput1, - `This Assertion is fails when it's a proper fraction - current output: ${currentOutput}, target output: ${targetOutput1} ` + currentOutput1 === targetOutput1, + `current output: ${currentOutput1}, target output: ${targetOutput1} ` ); diff --git a/week-3/refactor/format-as-12-hours.js b/week-3/refactor/format-as-12-hours.js index 41603122..01921371 100644 --- a/week-3/refactor/format-as-12-hours.js +++ b/week-3/refactor/format-as-12-hours.js @@ -4,3 +4,40 @@ // 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 +// I already stored it in a variable in first problem because we are using same thing twice which can make code look +// confusing and by storing it in variable it makes things easier for someone unfamiliar with code to understand. +function formatAs12HourClock(time) { + if (Number(time.slice(0, 2)) > 12) { + let timeFormat = Number(time.slice(0, 2)) - 12; + if (timeFormat < 10) return `0${timeFormat}:${time.slice(3, 5)} pm`; + else return `${timeFormat}:${time.slice(3, 5)} 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 +); + +const currentOutput1 = formatAs12HourClock("17:42"); +const targetOutput1 = "05:42 pm"; +console.assert( + currentOutput1 === targetOutput1, + `current output: %s, target output: %s`, + currentOutput1, + targetOutput1 +); \ No newline at end of file diff --git a/week-3/refactor/is-vowel.js b/week-3/refactor/is-vowel.js index db675d2b..2d2dee0e 100644 --- a/week-3/refactor/is-vowel.js +++ b/week-3/refactor/is-vowel.js @@ -2,8 +2,7 @@ function isVowel(letter) { return ( letter === "a" || letter === "e" || - letter === "i" || - letter === "i" || + letter === "i" ||// removed same line twice in the function here letter === "o" || letter === "u" ); @@ -40,3 +39,13 @@ console.assert( currentOutput3, targetOutput3 ); + +console.log("case: letter i..."); +const currentOutput4 = isVowel("i"); +const targetOutput4 = true; +console.assert( + currentOutput4 === targetOutput4, + "current output: %s, target output: %s", + currentOutput4, + targetOutput4 +); From 070482867881594469481de313e1bd98108d3b9c Mon Sep 17 00:00:00 2001 From: areebsattar Date: Sat, 2 Dec 2023 14:30:18 +0000 Subject: [PATCH 5/6] Tried refactoring is-proper-function --- week-3/implement/is-proper-fraction.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/week-3/implement/is-proper-fraction.js b/week-3/implement/is-proper-fraction.js index 6851292e..4d058ed7 100644 --- a/week-3/implement/is-proper-fraction.js +++ b/week-3/implement/is-proper-fraction.js @@ -1,6 +1,8 @@ // You wil need to implement a function isProperFraction // You need to write assertions for your function to check it works in different cases +const { log } = require("console"); + // Terms: // Fractions: https://www.bbc.co.uk/bitesize/topics/zt9n6g8/articles/zjxpp4j // Written here like this: 1/2 == Numerator/Denominator @@ -38,20 +40,22 @@ function isProperFraction (a,b){ if (ab){ + if(a>b){ return false; } - else if (b=0){ - return ; + if (b===0){ + return "error"; } - else if (a<0){ + if (a<0){ return true; } - else if (a===b){ + if (a===b){ return false; } } +console.log(isProperFraction(3,0)); + console.log("This Assertion is fails when it's not a proper fraction"); const currentOutput = isProperFraction(8,9); const targetOutput = true; From 0374d9392a90c73875adfd622a1f078b433a3741 Mon Sep 17 00:00:00 2001 From: areebsattar Date: Sun, 3 Dec 2023 14:37:48 +0000 Subject: [PATCH 6/6] update --- week-3/implement/get-angle-type.js | 3 +- week-3/implement/is-proper-fraction.js | 39 +++++++++++++------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/week-3/implement/get-angle-type.js b/week-3/implement/get-angle-type.js index 4166d2ca..7622f74c 100644 --- a/week-3/implement/get-angle-type.js +++ b/week-3/implement/get-angle-type.js @@ -43,4 +43,5 @@ function getAngleType(angle){ return "Angle cannot be greater than 360 or less than 0" } -console.log (getAngleType(90)); \ No newline at end of file +console.log(getAngleType(90)); + diff --git a/week-3/implement/is-proper-fraction.js b/week-3/implement/is-proper-fraction.js index 4d058ed7..9c8edbef 100644 --- a/week-3/implement/is-proper-fraction.js +++ b/week-3/implement/is-proper-fraction.js @@ -36,28 +36,28 @@ const { log } = require("console"); // 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 (a,b){ - if (ab){ - return false; - } - if (b===0){ - return "error"; - } - if (a<0){ - return true; - } - if (a===b){ - return false; - } +function isProperFraction(a, b) { + if (b === 0) { + return "error"; + } + if (a < b) { + return true; + } + if (a > b) { + return false; + } + if (a < 0) { + return true; + } + if (a === b) { + return false; + } } -console.log(isProperFraction(3,0)); +console.log(isProperFraction(3, 3)); console.log("This Assertion is fails when it's not a proper fraction"); -const currentOutput = isProperFraction(8,9); +const currentOutput = isProperFraction(8, 9); const targetOutput = true; console.assert( currentOutput === targetOutput, @@ -65,10 +65,9 @@ console.assert( ); console.log("This Assertion is fails when it's a proper fraction"); -const currentOutput1 = isProperFraction(8, 4); +const currentOutput1 = isProperFraction(8, 4); const targetOutput1 = false; console.assert( currentOutput1 === targetOutput1, `current output: ${currentOutput1}, target output: ${targetOutput1} ` ); -