Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
debug code
Browse files Browse the repository at this point in the history
nohetekelmariyam committed Dec 3, 2023
1 parent 0c7233b commit 54674d0
Showing 7 changed files with 93 additions and 3 deletions.
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`;
}
@@ -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
@@ -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));
14 changes: 14 additions & 0 deletions week-3/implement/get-card-value.js
Original file line number Diff line number Diff line change
@@ -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
@@ -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));
13 changes: 13 additions & 0 deletions week-3/implement/is-valid-triangle.js
Original file line number Diff line number Diff line change
@@ -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";
}
}
26 changes: 26 additions & 0 deletions week-3/refactor/format-as-12-hours.js
Original file line number Diff line number Diff line change
@@ -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
);
3 changes: 1 addition & 2 deletions week-3/refactor/is-vowel.js
Original file line number Diff line number Diff line change
@@ -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...");

0 comments on commit 54674d0

Please sign in to comment.