From 2adc78db5f463f62bca6e2dfd055fe2bc2b38007 Mon Sep 17 00:00:00 2001 From: bahador Date: Wed, 18 Oct 2023 16:52:51 +0100 Subject: [PATCH 1/2] completed implement --- week-3/debug/format-as-12-hours.js | 84 +++++++++++++++++++++++++- week-3/implement/get-angle-type.js | 63 +++++++++++++++++++ week-3/implement/get-card-value.js | 15 +++++ week-3/implement/is-proper-fraction.js | 45 ++++++++++++++ week-3/implement/is-valid-triangle.js | 14 +++++ 5 files changed, 219 insertions(+), 2 deletions(-) diff --git a/week-3/debug/format-as-12-hours.js b/week-3/debug/format-as-12-hours.js index 56b83a5b..2114a699 100644 --- a/week-3/debug/format-as-12-hours.js +++ b/week-3/debug/format-as-12-hours.js @@ -1,6 +1,8 @@ function formatAs12HourClock(time) { - if (Number(time.slice(0, 2)) > 12) { - return `${Number(time.slice(0, 2)) - 12}:00 pm`; + let sliceStorage = Number(time.slice(0, 2)) > 12; + let calculateTime = `${Number(time.slice(0, 2)) - 12}`; + if (sliceStorage) { + return `${calculateTime}:00 pm`; } return `${time} am`; } @@ -23,8 +25,86 @@ console.assert( targetOutput2 ); +const currentOutput3 = formatAs12HourClock("17:42"); +const targetOutput3 = "07:00 pm"; +console.assert( + currentOutput3 === targetOutput3, + "current output: %s, target output: %s", + currentOutput2, + targetOutput2 +); + // formatAs12HourClock currently has a 🐛 // a) Write an assertion to check the return value of formatAs12HourClock when it is called with an input "17:42" +// const result = formatAs12HourClock("17:42"); +// console.log(result); // Output should be "5:42 pm" +//The assert() method tests if a given expression is true or not. + // b) Check the assertion output and explain what the bug is +//To fix this bug, you should modify the code to check if the hours are greater than or equal to 12 (12 or greater) instead of just greater than 12. This change ensures that "12:00" is correctly interpreted as noon. +// With this fix, the function will now produce the expected output of "12:00 pm" when the input is "12:00." + // c) Now fix the bug and re-run all your assertions + +// // Exercise 1 +// // line o1 +// const check = true === false; +// console.log(check); + +// //line 2 +// const check1 = 5 == 2 + 4; +// console.log(check1); + +// //line 3 +// const check2 = 4 * 5 == "20"; +// console.log(check2); + +// //line 4 +// const check4 = 3 * 2 === 6; +// console.log(check4); + +// // line 5 +// const check5 = Math.min(3, 4, 5) === 4; +// console.log(check5); + +// // line 6 +// let mhairiName = "Mahiri"; +// typeof mhairiName === "string"; +// console.log(mhairiName); + +// let mhairiAge = 28; +// console.log(mhairiAge); + +// let isMhairiOldEnoughToDrive = true; +// console.log(isMhairiOldEnoughToDrive); + +// let kilometersMhairiDrivesToWork = 9.4; +// console.log(kilometersMhairiDrivesToWork); + +// const calculation = 10 + 32; +// const result = 40; +// //console.assert(calculation === result); + +// function formatAs12HourClock(time) { +// return `${time} am`; +// } + +// const currentOutput = formatAs12HourClock("08:00"); +// const targetOutput = "08:00 am"; + +// console.assert( +// currentOutput === targetOutput, +// "current function output: %s, target output: %s", +// currentOutput, +// targetOutput +// ); + +// const currentOutput2 = formatAs12HourClock("23:00"); +// const targetOutput2 = "11:00 am"; +// console.assert( +// currentOutput2 === targetOutput2, +// "current output: %s, target output: %s", +// currentOutput2, +// targetOutput2 +// ); diff --git a/week-3/implement/get-angle-type.js b/week-3/implement/get-angle-type.js index db952494..3b03ca08 100644 --- a/week-3/implement/get-angle-type.js +++ b/week-3/implement/get-angle-type.js @@ -25,3 +25,66 @@ // 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 (typeof angle === "number" && angle >= 0 && angle <= 360) { + 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 return "Reflex angle"; + } else return " Value should be a number between 0 & 360"; +} + +const currentOutput = getAngleType(90); //-->actual value +const targetOutput = "Right angle"; //--> idea +console.assert( + currentOutput == targetOutput, + "current output: %s, target output: %s 1", + currentOutput, + targetOutput +); + +const currentOutput1 = getAngleType(30); //-->actual value +const targetOutput1 = "Acute angle"; //--> idea +console.assert( + currentOutput1 == targetOutput1, + "current output: %s, target output: %s 2", + currentOutput1, + targetOutput1 +); + +const currentOutput2 = getAngleType(120); //-->actual value +const targetOutput2 = "Obtuse angle"; //--> idea +console.assert( + currentOutput2 == targetOutput2, + "current output: %s, target output: %s 3", + currentOutput2, + targetOutput2 +); + +const currentOutput3 = getAngleType(180); +const targetOutput3 = "Straight angle"; +console.assert( + currentOutput3 == targetOutput3, + "current output: %s, target output: %s 4", + currentOutput3, + targetOutput3 +); +const currentOutput4 = getAngleType(185); +const targetOutput4 = "Reflex angle"; +console.assert( + currentOutput4 == targetOutput4, + "current output: %s, target output: %s 5", + currentOutput4, + targetOutput4 +); + +console.log(getAngleType(360)); +console.log(getAngleType(true)); +console.log(getAngleType(-120)); +// completed with Withe Elmira diff --git a/week-3/implement/get-card-value.js b/week-3/implement/get-card-value.js index 84723845..d4337544 100644 --- a/week-3/implement/get-card-value.js +++ b/week-3/implement/get-card-value.js @@ -29,3 +29,18 @@ // 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) { + const numberCards = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]; + const faceCard = ["10", "J", "Q", "k"]; + cardValue = cardValue[0]; + if (numberCards.includes(cardValue)) { + return Number(cardValue); + } else if (faceCard.includes(cardValue)) { + return 10; + } else if (cardValue === "A") { + return 11; + } else return `please a valid card`; +} +console.log(getCardValue(5)); + +// completed with Withe Elmira diff --git a/week-3/implement/is-proper-fraction.js b/week-3/implement/is-proper-fraction.js index 6493da0b..805e676d 100644 --- a/week-3/implement/is-proper-fraction.js +++ b/week-3/implement/is-proper-fraction.js @@ -32,3 +32,48 @@ // 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. // 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 (denominator === 0) { + return "Error: Denominator cannot be zero"; + } else if (numerator >= denominator) { + return `The fraction ${numerator}/${denominator} is an improper fraction`; + } else if (numerator < 0) { + return `The fraction is ${numerator}/${denominator} a proper fraction`; + } else { + return `The fraction ${numerator}/${denominator} is a proper fraction`; + } +} + +// console.log(isProperFraction(5,3)); +// const currentOutput=isProperFraction(3,5); +// const targetOutput="is a fraction"; +// console.assert(currentOutput==targetOutput, +// "current output: %s, target output: %s 1", +// currentOutput, +// targetOutput +// ); + +// const currentOutput1=isProperFraction(5,3); +// const targetOutput1="Not a valid fraction"; +// console.assert(currentOutput1==targetOutput1, +// "current output: %s, target output: %s 2", +// currentOutput1, +// targetOutput1 +// ); + +// const currentOutput2=isProperFraction(-4,8); +// const targetOutput2="`The fraction is ${numerator} a proper fraction`"; +// console.assert(currentOutput2==targetOutput2, +// "current output: %s, target output: %s 3", +// currentOutput2, +// targetOutput2 +// ); + +console.log(isProperFraction(-4, 8)); +console.log(isProperFraction(-4, 0)); +console.log(isProperFraction(-4, 0)); +console.log(isProperFraction(5, 2)); +console.log(isProperFraction(6, 6)); +console.log(isProperFraction(6, -8)); +// completed with Withe Elmira diff --git a/week-3/implement/is-valid-triangle.js b/week-3/implement/is-valid-triangle.js index 432ef338..7cf6896f 100644 --- a/week-3/implement/is-valid-triangle.js +++ b/week-3/implement/is-valid-triangle.js @@ -37,3 +37,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 <= 0 || b <= 0 || c <= 0) { + return `Not a valid triangle`; + } else if (a + b > c && b + c > a && c + a > b) { + return `is a valid triangle`; + } else { + return `Not a valid triangle`; + } +} + +console.log(isValidTriangle(1, 0, 3)); +console.log(isValidTriangle(-2, 0, 3)); +console.log(isValidTriangle(6, 6, 3)); +// completed with Withe Elmira From 216151698f486e59bfd7b708a1bb6648d5a6e366 Mon Sep 17 00:00:00 2001 From: bahador Date: Wed, 18 Oct 2023 20:11:10 +0100 Subject: [PATCH 2/2] completed week3 Excercises --- week-3/refactor/format-as-12-hours.js | 4 ++++ week-3/refactor/is-vowel.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/week-3/refactor/format-as-12-hours.js b/week-3/refactor/format-as-12-hours.js index 5e6f541b..11687288 100644 --- a/week-3/refactor/format-as-12-hours.js +++ b/week-3/refactor/format-as-12-hours.js @@ -3,3 +3,7 @@ // 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 + +//when we stor this expression in a variable help us for good code Readability and Maintainability - +// we can Reuse our code, if we use the same expression multiple times in our code. +// it also help our code to be clear, if we store them in a variable with a meaningful name can help clarify the purpose of the expression and the sequence of operations bing performed. diff --git a/week-3/refactor/is-vowel.js b/week-3/refactor/is-vowel.js index db675d2b..ad912e19 100644 --- a/week-3/refactor/is-vowel.js +++ b/week-3/refactor/is-vowel.js @@ -9,7 +9,7 @@ function isVowel(letter) { ); } -// here is an implementation of isVowel - this function checks if a letter is a vowel +//here is an implementation of isVowel - this function checks if a letter is a vowel console.log("case: letter a..."); const currentOutput = isVowel("a");