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

NW6 | Hadika Malik | Module JS1 | Week 4 #187

Open
wants to merge 4 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
20 changes: 17 additions & 3 deletions week-3/debug/format-as-12-hours.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
function formatAs12HourClock(time) {
if (Number(time.slice(0, 2)) > 12) {
return `${Number(time.slice(0, 2)) - 12}:00 pm`;
let timeFormat = (Number(time.slice(0, 2)) - 12)
if (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`;
Comment on lines +2 to +7
Copy link
Contributor

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.

Copy link
Contributor

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.

}
return `${time} am`;
}
Expand All @@ -23,8 +27,18 @@ console.assert(
targetOutput2
);

const currentOutput3 = formatAs12HourClock("17:42");
const targetOutput3 = "05: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
// b) Check the assertion output and explain what the bug is // it wasnt returning the minutes and wasnt adding a zero infront of 5
// c) Now fix the bug and re-run all your assertions
23 changes: 0 additions & 23 deletions week-3/implement/get-angle-type.js

This file was deleted.

55 changes: 55 additions & 0 deletions week-3/implement/get-angle-type.test.js
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");
});
31 changes: 0 additions & 31 deletions week-3/implement/get-card-value.js

This file was deleted.

82 changes: 82 additions & 0 deletions week-3/implement/get-card-value.test.js
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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):

Given a card string in the format "A♠" (representing a card in blackjack),


}

// 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');
});
35 changes: 0 additions & 35 deletions week-3/implement/is-proper-fraction.js

This file was deleted.

108 changes: 108 additions & 0 deletions week-3/implement/is-proper-fraction.test.js
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
Copy link
Contributor

Choose a reason for hiding this comment

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

First of all, we shouldn't return 'True' and 'False' as strings. These should be boolean types true and false.
Secondly, you have 2 checks which return true, and 2 checks which return false. Could you please try to merge/combine them to have only one check instead (or at least 2)?


// 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');
});
Loading