Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

NW6 | Nohe-Tekelmariyam | JS1-Module | Week-3 #185

Open
wants to merge 1 commit 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
12 changes: 11 additions & 1 deletion week-3/debug/format-as-12-hours.js
Original file line number Diff line number Diff line change
@@ -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`;
}
Expand All @@ -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
15 changes: 15 additions & 0 deletions week-3/implement/get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link

Choose a reason for hiding this comment

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

start your variable name with a small letter, i.e angles instead of 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) {
Copy link

Choose a reason for hiding this comment

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

your variable name is not AnglesS change that, this code wont run

return "reflex angle";
} else {
return "it's not angle";
}
}
var AngleS = 350;
Copy link

Choose a reason for hiding this comment

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

small letter for starting variable name. Also use const to declare a variable if the value will never change

console.log(getAngleType(AngleS));
14 changes: 14 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,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♠"));
13 changes: 13 additions & 0 deletions week-3/implement/is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link

Choose a reason for hiding this comment

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

you should take care of error first, check if the denomiator is 0 then return an error, then go to do the next check.

return "false";
} else if (numerator < denominator) {
return "True";
Copy link

Choose a reason for hiding this comment

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

a boolean true does not start with a capital letter

} else {
return "error";
}
}
console.log(isProperFraction(5, 2));
console.log(isProperFraction(3, 0));
console.log(isProperFraction(-4, 7));
console.log(isProperFraction(3, 3));
13 changes: 13 additions & 0 deletions week-3/implement/is-valid-triangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Copy link

Choose a reason for hiding this comment

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

why is there no standalone check for side1 <= 0 ?

side3 <= 0
) {
return "false";
} else {
return "turn";
Copy link

Choose a reason for hiding this comment

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

you are returning turn here

}
}
26 changes: 26 additions & 0 deletions week-3/refactor/format-as-12-hours.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Copy link

Choose a reason for hiding this comment

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

if a value like 18:46 is send in here, the result according to your code will be 6:00pm which is wrong. Also is the time send is 09:00 the result will be 09:00 without the am appended. You need to take care of these cases

}
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
);
3 changes: 1 addition & 2 deletions week-3/refactor/is-vowel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...");
Expand Down