Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.
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
7 changes: 6 additions & 1 deletion week-1/exercises/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
console.log(`The base part of ${filePath} is ${base}`);
//console.log(`The base part of ${filePath} is ${base}`);

// Create a variable to store the dir part of the filePath variable
// Create a variable to store the ext part of the variable
// const dirPart = filePath.slice(0, lastSlashIndex);
// console.log(dirPart);

const extPart = filePath.lastIndexOf(".");
console.log(extPart);
25 changes: 23 additions & 2 deletions week-3/debug/format-as-12-hours.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
// function formatAs12HourClock() {

// }

// console.assert(formatAs12HourClock("04:00")==='05:00 am')

// 04<12 --> 04 am;
//18>12 ---> 18-12=6 pm


function formatAs12HourClock(time) {
if (Number(time.slice(0, 2)) > 12) {
return `${Number(time.slice(0, 2)) - 12}:00 pm`;
let sliceStorage = Number(time.slice(0, 2)) > 12;
let calculateTime = `${Number(time.slice(0, 2)) - 12}`;

if (sliceStorage) {
return `${calculateTime}:00 pm`;
}
return `${time} am`;
}
Expand All @@ -26,5 +39,13 @@ console.assert(
// formatAs12HourClock currently has a 🐛

// a) Write an assertion to check the return value of formatAs12HourClock when it is called with an input "17:42"
// const result = formatAs12HourClock("17:42");
// console.log(result); // Output should be "5:42 pm"
//The assert() method tests if a given expression is true or not.

// b) Check the assertion output and explain what the bug is

//To fix this bug, you should modify the code to check if the hours are greater than or equal to 12 (12 or greater) instead of just greater than 12. This change ensures that "12:00" is correctly interpreted as noon.
// With this fix, the function will now produce the expected output of "12:00 pm" when the input is "12:00."

// c) Now fix the bug and re-run all your assertions
67 changes: 66 additions & 1 deletion week-3/implement/get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Implement a function getAngleType
// Implement a function getAngleType

// Acceptance criteria:

Expand All @@ -25,3 +25,68 @@
// 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 (typeof angle=== 'number'&& angle>=0 && angle<=360){
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 return "Reflex angle";


}
else
return ' Value should be a number between 0 & 360';
}


const currentOutput=getAngleType(90);//-->actual value
const targetOutput="Right angle";//--> idea
console.assert(currentOutput==targetOutput,
"current output: %s, target output: %s 1",
currentOutput,
targetOutput
);

const currentOutput1=getAngleType(30);//-->actual value
const targetOutput1="Acute angle";//--> idea
console.assert(currentOutput1==targetOutput1,
"current output: %s, target output: %s 2",
currentOutput1,
targetOutput1
);

const currentOutput2=getAngleType(120);//-->actual value
const targetOutput2="Obtuse angle";//--> idea
console.assert(currentOutput2==targetOutput2,
"current output: %s, target output: %s 3",
currentOutput2,
targetOutput2
);

const currentOutput3=getAngleType(180);
const targetOutput3="Straight angle";
console.assert(currentOutput3==targetOutput3,
"current output: %s, target output: %s 4",
currentOutput3,
targetOutput3
);
const currentOutput4=getAngleType(185);
const targetOutput4="Reflex angle";
console.assert(currentOutput4==targetOutput4,
"current output: %s, target output: %s 5",
currentOutput4,
targetOutput4
);

console.log(getAngleType(360));
console.log(getAngleType(true));
console.log(getAngleType(-120));
29 changes: 29 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,32 @@
// 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) {
const numberCards=['2','3','4','5','6','7','8','9'];
const faceCards=["10" ,"J", "Q", "K"];
cardValue = cardValue[0];
if (numberCards.includes(cardValue)){
return Number(cardValue);

}
else if(faceCards.includes(cardValue)){
return 10;

}
else if(cardValue==='A') {
return 11;
}
else return 'please enter a valid card value'




}
console.log(getCardValue('5'));



// let card = 5;
// card = card+2;
// console.log(card);
51 changes: 51 additions & 0 deletions week-3/implement/is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,54 @@
// 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 isProperFraction(numerator,denominator) {
if (denominator === 0){
return "Error: Denominator cannot be zero";

}
else if (numerator >= denominator) {
return `The fraction ${numerator}/${denominator} is an improper fraction`;
}
else if (numerator<0){
return `The fraction is ${numerator}/${denominator} a proper fraction`;
}
else {
return `The fraction ${numerator}/${denominator} is a proper fraction`;
}

}


// console.log(isProperFraction(5,3));
// const currentOutput=isProperFraction(3,5);
// const targetOutput="is a fraction";
// console.assert(currentOutput==targetOutput,
// "current output: %s, target output: %s 1",
// currentOutput,
// targetOutput
// );

// const currentOutput1=isProperFraction(5,3);
// const targetOutput1="Not a valid fraction";
// console.assert(currentOutput1==targetOutput1,
// "current output: %s, target output: %s 2",
// currentOutput1,
// targetOutput1
// );

// const currentOutput2=isProperFraction(-4,8);
// const targetOutput2="`The fraction is ${numerator} a proper fraction`";
// console.assert(currentOutput2==targetOutput2,
// "current output: %s, target output: %s 3",
// currentOutput2,
// targetOutput2
// );

console.log(isProperFraction(-4,8));
console.log(isProperFraction(-4,0));
console.log(isProperFraction(-4,0));
console.log(isProperFraction(5,2));
console.log(isProperFraction(6,6));
console.log(isProperFraction(6,-8));


20 changes: 20 additions & 0 deletions week-3/implement/is-valid-triangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,23 @@
// 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 <=0 || b <=0 || c <=0){
return `Not a valid triangle`;
}
else if (a + b > c && b + c > a && c + a > b){
return `is a valid triangle`;
}
else {
return `Not a valid triangle`;
}
}

console.log(isValidTriangle(1,0,3));
console.log(isValidTriangle(-2,0,3));
console.log(isValidTriangle(6,6,3));

// worked with Bahadory to gether



8 changes: 8 additions & 0 deletions week-3/refactor/format-as-12-hours.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
// 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


// Explanation:
// Storing the expression in a variable enhances the readability of the code and makes it easier to understand the purpose of that particular value. Additionally, by storing it in a variable, you avoid recalculating the same value multiple times.