-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
NW-6 | AREEB-SATTAR | JS1| [TECH ED] Complete week 3 exercises | WEEK-3 #154
base: main
Are you sure you want to change the base?
Changes from all commits
05330b8
5102fc4
fe54403
d6ba89a
0704828
0374d93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,27 @@ | |
// 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. an angle of 360 itself is not taken care of |
||
return "Angle cannot be greater than 360 or less than 0" | ||
} | ||
|
||
console.log(getAngleType(90)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,46 @@ | |
// 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Be careful of the acceptance criteria on line 9. |
||
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")); | ||
|
||
console.log("Checking result for 2"); | ||
const currentOutput = getCardValue("2"); | ||
const targetOutput = 2; | ||
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( | ||
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( | ||
currentOutput2 === targetOutput2, | ||
`current output: ${currentOutput2}, target output: ${targetOutput2} ` | ||
); | ||
|
||
console.log("Checking result for A"); | ||
const currentOutput3 = getCardValue("A"); | ||
const targetOutput3 = 11; | ||
console.assert( | ||
currentOutput3 === targetOutput3, | ||
`current output: ${currentOutput3}, target output: ${targetOutput3} ` | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
@@ -33,3 +35,39 @@ | |
// 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you think will happen when we pass |
||
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, 3)); | ||
|
||
console.log("This Assertion is fails when it's not a proper fraction"); | ||
const currentOutput = isProperFraction(8, 9); | ||
const targetOutput = true; | ||
console.assert( | ||
currentOutput === 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( | ||
currentOutput1 === targetOutput1, | ||
`current output: ${currentOutput1}, target output: ${targetOutput1} ` | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic here is the opposite of the logic on line 43. For example, For that reason the checks here on line 49 aren't necessary |
||
return true; | ||
} | ||
} | ||
|
||
console.log(isValidTriangle(3,3,3)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can take this further. What if we moved the expression |
||
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 | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you think of a way this can be done without an
if
statement? JavaScript's standard library has a great function for this use case 😉