-
-
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
NW6 | Hadika Malik | Module JS1 | Week 4 #187
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Implement a function getAngleType, and tests for each of the acceptance criteria. | ||
|
||
// Acceptance criteria: | ||
|
||
// Identify Right Angles: | ||
// When the angle is exactly 90 degrees, | ||
// Then the function should return "Right angle" | ||
|
||
// Identify Acute Angles: | ||
// When the angle is less than 90 degrees, | ||
// Then the function should return "Acute angle" | ||
|
||
// Identify Obtuse Angles: | ||
// When the angle is greater than 90 degrees and less than 180 degrees, | ||
// Then the function should return "Obtuse angle" | ||
|
||
// Identify Straight Angles: | ||
// When the angle is exactly 180 degrees, | ||
// Then the function should return "Straight angle" | ||
|
||
// Identify Reflex Angles: | ||
// When the angle is greater than 180 degrees and less than 360 degrees, | ||
// Then the function should return "Reflex angle" | ||
|
||
function triangleAngle(degrees){ | ||
if (degrees === 90) | ||
return 'Right angle'; | ||
|
||
else if (degrees < 90) | ||
return 'Acute angle'; | ||
|
||
else if (degrees > 90 && degrees < 180) | ||
return 'Obtuse'; | ||
|
||
else if (degrees === 180) | ||
return 'Straight angle' | ||
|
||
else if (degrees > 180 && degrees < 360) | ||
return 'Reflex angle' | ||
|
||
} | ||
|
||
// console.log(triangleAngle(90)); | ||
// console.log(triangleAngle(45)); | ||
// console.log(triangleAngle(105)); | ||
// console.log(triangleAngle(180)); | ||
// console.log(triangleAngle(220)); | ||
|
||
test("idenity the angle type", function () { | ||
expect(triangleAngle(90)).toBe("Right angle"); | ||
expect(triangleAngle(45)).toBe("Acute angle"); | ||
expect(triangleAngle(105)).toBe("Obtuse"); | ||
expect(triangleAngle(180)).toBe("Straight angle"); | ||
expect(triangleAngle(220)).toBe("Reflex angle"); | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck | ||
|
||
// You will need to implement a function getCardValue | ||
|
||
// You need to write assertions for your function to check it works in different cases | ||
|
||
// Acceptance criteria: | ||
|
||
// Given a card string in the format "A♠" (representing a card in blackjack), | ||
// When the function getCardValue is called with this card string as input, | ||
// Then it should return the numerical card value | ||
|
||
// Handle Number Cards (2-10): | ||
// Given a card with a rank between "2" and "10", | ||
// When the function is called with such a card, | ||
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). | ||
|
||
// Handle Face Cards (J, Q, K): | ||
// Given a card with a rank of "J," "Q," or "K", | ||
// When the function is called with such a card, | ||
// Then it should return the value 10, as these cards are worth 10 points each in blackjack. | ||
|
||
// Handle Ace (A): | ||
// Given a card with a rank of "A", | ||
// When the function is called with an Ace, | ||
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. | ||
|
||
// Handle Invalid Cards: | ||
// 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(cardString){ | ||
|
||
if (cardString > 1 && cardString < 11) | ||
return +cardString; | ||
|
||
else if (cardString === 'J' || cardString === 'Q' || cardString === 'K') | ||
return 10 | ||
|
||
else if (cardString === 'A') | ||
return 11 | ||
|
||
else | ||
return 'Invalid card rank' | ||
Comment on lines
+35
to
+45
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 this solution is missing something (second part of the card string):
|
||
|
||
} | ||
|
||
// console.log(getCardValue(10)); | ||
// console.log(getCardValue('J')); | ||
// console.log(getCardValue('A')); | ||
// console.log(getCardValue('Z')); | ||
|
||
// const currentOutput = getCardValue('K'); | ||
// const targetOutput = 5 | ||
// const targetOutput1 = 10 | ||
// const targetOutput2 = 11 | ||
// const targetOutput3 = "Invalid card rank" | ||
|
||
// console.assert( | ||
// currentOutput === targetOutput, | ||
// `current output: ${currentOutput}, target output: ${targetOutput}` | ||
// ) | ||
// console.assert( | ||
// currentOutput === targetOutput1, | ||
// `current output: ${currentOutput}, target output: ${targetOutput1}` | ||
// ) | ||
// console.assert( | ||
// currentOutput === targetOutput2, | ||
// `current output: ${currentOutput}, target output: ${targetOutput2}` | ||
// ) | ||
// console.assert( | ||
// currentOutput === targetOutput3, | ||
// `current output: ${currentOutput}, target output: ${targetOutput3}` | ||
// ); | ||
|
||
test("checks card value", function () { | ||
expect(getCardValue(10)).toBe(10); | ||
expect(getCardValue(`J`)).toBe(10); | ||
expect(getCardValue(`A`)).toBe(11); | ||
expect(getCardValue(`Z`)).toBe('Invalid card rank'); | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// You wil need to implement a function isProperFraction | ||
// You need to write assertions for your function to check it works in different cases | ||
|
||
// Terms: | ||
// Fractions: https://www.bbc.co.uk/bitesize/topics/zt9n6g8/articles/zjxpp4j | ||
// Written here like this: 1/2 == Numerator/Denominator | ||
|
||
// Acceptance criteria: | ||
|
||
// Proper Fraction check: | ||
// Input: numerator = 2, denominator = 3 | ||
// target output: true | ||
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true. | ||
|
||
// Improper Fraction check: | ||
// Input: numerator = 5, denominator = 2 | ||
// target output: false | ||
// Explanation: The fraction 5/2 is an improper fraction, where the numerator is greater than or equal to the denominator. The function should return false. | ||
|
||
// Zero Denominator check: | ||
// Input: numerator = 3, denominator = 0 | ||
// No target output: Error (Denominator cannot be zero) | ||
// Explanation: The function should throw an error when the denominator is zero, as it's not a valid fraction. | ||
|
||
// Negative Fraction check: | ||
// Input: numerator = -4, denominator = 7 | ||
// target output: true | ||
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true. | ||
|
||
// Equal Numerator and Denominator check: | ||
// Input: numerator = 3, denominator = 3 | ||
// 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 properFraction(num,den){ | ||
|
||
if (den === 0) | ||
return 'Error'; | ||
|
||
if (num < den) | ||
return 'True'; | ||
|
||
if (num > den || num === den) | ||
return 'False'; | ||
|
||
if (num < 0 && num < den) | ||
return 'True'; | ||
|
||
if (num === den) | ||
return 'False'; | ||
|
||
} | ||
Comment on lines
+37
to
+54
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. First of all, we shouldn't return |
||
|
||
// console.log(properFraction(2,3)); | ||
// console.log(properFraction(5,2)); | ||
// console.log(properFraction(3,0)); | ||
// console.log(properFraction(-4,7)); | ||
// console.log(properFraction(3,3)); | ||
|
||
// const currentOutput = properFraction(2,3); | ||
// const targetOutput = 'True' | ||
|
||
// console.assert( | ||
// currentOutput === targetOutput, | ||
// `current output: ${currentOutput}, target output: ${targetOutput}` | ||
// ) | ||
|
||
// const currentOutput1 = properFraction(5,2); | ||
// const targetOutput1 = 'False' | ||
|
||
// console.assert( | ||
// currentOutput1 === targetOutput1, | ||
// `current output: ${currentOutput1}, target output: ${targetOutput1}` | ||
// ) | ||
|
||
// const currentOutput2 = properFraction(3,0); | ||
// const targetOutput2 = 'Error' | ||
|
||
// console.assert( | ||
// currentOutput2 === targetOutput2, | ||
// `current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
// ) | ||
|
||
// const currentOutput3 = properFraction(-4,7); | ||
// const targetOutput3 = 'True' | ||
|
||
// console.assert( | ||
// currentOutput3 === targetOutput3, | ||
// `current output: ${currentOutput3}, target output: ${targetOutput3}` | ||
// ) | ||
|
||
// const currentOutput4 = properFraction(3,3); | ||
// const targetOutput4 = 'False' | ||
|
||
// console.assert( | ||
// currentOutput4 === targetOutput4, | ||
// `current output: ${currentOutput4}, target output: ${targetOutput4}` | ||
// ) | ||
|
||
test("checks if fraction is proper fraction", function () { | ||
expect(properFraction(2,3)).toBe(`True`); | ||
expect(properFraction(5,2)).toBe(`False`); | ||
expect(properFraction(3,0)).toBe(`Error`); | ||
expect(properFraction(-4,7)).toBe('True'); | ||
expect(properFraction(3,3)).toBe('False'); | ||
}); |
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.
Please watch code formatting. The alignment of each line is different which is not right.
Try using VS Code Extension Prettier which helps you to format your code on saving document.
Also some semicolons are missing (in the end of the first line). Prettier can help you with both problems.
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.
This comment is relevant to all the files.