Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WM5 | BAHADORY| Module-JS1| week3 #100

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 82 additions & 2 deletions week-3/debug/format-as-12-hours.js
Original file line number Diff line number Diff line change
@@ -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`;
}
Expand All @@ -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
// );
63 changes: 63 additions & 0 deletions week-3/implement/get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good and performs as it should.

// completed with Withe Elmira
15 changes: 15 additions & 0 deletions week-3/implement/get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks to be functional.


// completed with Withe Elmira
45 changes: 45 additions & 0 deletions week-3/implement/is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions week-3/implement/is-valid-triangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions week-3/refactor/format-as-12-hours.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion week-3/refactor/is-vowel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down