Skip to content

London | May-2025 | Ikenna Agulobi | Structuring and Testing Data sprint-3 #614

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

Open
wants to merge 39 commits into
base: to-be-deleted-coursework/sprint-3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4c2c13b
Update pull_request_template.md (#450)
cjyuan May 6, 2025
d82bbed
I added a comment to explain the error message in the exercise 1-key-…
ike-agu Jun 10, 2025
2cb3fd1
Fixed the error in exercise 1-key-errors/1.js and Added a comment to …
ike-agu Jun 10, 2025
c55e7cc
Fixed the error in exercise 1-key-errors/2.js and Added a comment to …
ike-agu Jun 10, 2025
1a393b4
I commented out the failing funtions in both execise 1-key-errors/0.…
ike-agu Jun 10, 2025
a858622
Fixed the error in 2-mandatory-debug/0.js and added a comment to exp…
ike-agu Jun 10, 2025
cad472b
fixed the error in 2-mandatory-debug/1.js exercise and added a commen…
ike-agu Jun 11, 2025
3bbfd7d
added a console.log to print out the result of calling the function
ike-agu Jun 11, 2025
fae5013
Added num to fixed the Error and also added a comment to explain the …
ike-agu Jun 11, 2025
b797b61
I implemented a function that calculate the BMI of an adult baased on…
ike-agu Jun 11, 2025
193c68d
I wrote a function that turns lowercase words into upper snake case.
ike-agu Jun 13, 2025
559bb34
I wrote a function to convert pence to pounds
ike-agu Jun 13, 2025
caa3ceb
I added comments to respond to the questions and explained what is ha…
ike-agu Jun 13, 2025
28aa754
Implemented condition to check if angle is less than 90
ike-agu Jun 19, 2025
269d699
added conditional statements and assertions to complete exercise 1-ge…
ike-agu Jun 19, 2025
d80529b
added test assertions to complete exercise 2-is-proper-fraction
ike-agu Jun 19, 2025
c84661f
Impleneted function to get card value for exercise 3-get-card-value.js
ike-agu Jun 24, 2025
8b34639
added completed getAngleType funtion from Key-implement exercise
ike-agu Jun 24, 2025
b96ae9e
Added tests for get angle type exercise
ike-agu Jun 24, 2025
23a5ed1
added my isProperFraction function from key-implement
ike-agu Jun 24, 2025
5d7b143
I added tests is Proipoer Fraction exercise
ike-agu Jun 24, 2025
f012a9d
added codes from getCardValue function
ike-agu Jun 24, 2025
6a21a03
added tests for get card value exercise
ike-agu Jun 24, 2025
f0ab495
added completed getAngleType funtion from Key-implement exercise
ike-agu Jun 24, 2025
01d9fc6
added tests for getOrdinalNumber from 1 - 11
ike-agu Jun 24, 2025
a04cb2f
added tests cases for repeat.test exercise
ike-agu Jun 25, 2025
1f4dd06
Implemented credit card validator function
ike-agu Jun 26, 2025
a7f3d14
Added comments to answer questions regarding the function find and th…
ike-agu Jun 26, 2025
198ff59
implemented passwordValidator function
ike-agu Jul 3, 2025
1268781
added test to check if password has uppercase or lowercase letter
ike-agu Jul 3, 2025
652f14e
added test to check if password has atleast one number 0-9
ike-agu Jul 3, 2025
ad3b998
added test to check if password has atleast one non-aphanumeric symbols
ike-agu Jul 3, 2025
000134e
fixed test to check if password has already been used. Changed return…
ike-agu Jul 3, 2025
e7b1e94
Changed return message for password already been used to equals to f…
ike-agu Jul 3, 2025
41f95e5
Implemented get get ordinal number function
ike-agu Jul 3, 2025
26a60b0
fixed test cases for get ordinal numbers function
ike-agu Jul 4, 2025
fdb2cbc
fixed test case password has atleast 5 characters
ike-agu Jul 4, 2025
6f7984a
Implemented count Character function
ike-agu Jul 4, 2025
4ad048f
Implemented repeat function
ike-agu Jul 4, 2025
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
6 changes: 3 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

You must title your PR like this:

COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME

For example,

NW4 | Carol Owen | HTML-CSS-Module | Week1
London | May-2025 | Carol Owen | Sprint-1

Complete the task list below this message.
If your PR is rejected, check the task list.
Expand All @@ -18,7 +18,7 @@ If your PR is rejected, check the task list.
Self checklist

- [ ] I have committed my files one by one, on purpose, and for a reason
- [ ] I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
- [ ] I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
- [ ] I have tested my changes
- [ ] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/contributing/)
- [ ] My changes meet the [requirements](./README.md) of this task
Expand Down
20 changes: 16 additions & 4 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
// Predict and explain first...
// =============> write your prediction here
/* The function capitalise() is trying to return the first letter of a string capitalised. However our program will
fail because it's declaring a variable inside a function using the same name as the parameter that is passed to the function.
If I attempt to run the program, It will generate a SyntaxError stating that 'str' has already been declared.

*/

// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
// - The error is a SyntaxError stating that 'str' has already been declared.

function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
// function capitalise(str) {
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
// return str;
// }

// =============> write your explanation here
// To solve the Error, we can either store the string interpolation with a different variable name or we can return the string interpolation if we don't intend to reuse it.

// =============> write your new code here
function capitalise(str) {
let strCaps = `${str[0].toUpperCase()}${str.slice(1)}`;
return strCaps;
}
32 changes: 25 additions & 7 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
// Predict and explain first...
/*The function below is trying to convert a decimal number to percentage */

// Why will an error occur when this program runs?
// =============> write your prediction here

/*An error will occur because the program logs the parameter decimalNumber instead of the function*/
// Try playing computer with the example to work out what is going on

function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;
// function convertToPercentage(decimalNumber) {
// const decimalNumber = 0.5;
// const percentage = `${decimalNumber * 100}%`;

return percentage;
}
// return percentage;
// }

console.log(decimalNumber);
// console.log(decimalNumber);

// =============> write your explanation here
/*
- The function convertToPercentage() takes a parameter called decimalNumber
- it's declaring a constant variable with the parameter decimalNumber which will throw an error because it's withing the same scope and in JS is not allowed. Variable names suppose to be unique within the same scope.
- It's storing a hardcoded value of 0.5 as value to the constant variable decimalNumber
- It creates a constant variable percentage to store the value of multiplying decimalNumber by 100 to get the percentage
- It returns percentage
- Finally, it logs the parameter decimalNumber without the function which will generate an error.
*/

// Finally, correct the code to fix the problem
// =============> write your new code here

function convertToPercentage(decimalNumber) {
const decimalNumberValue = decimalNumber;
const percentage = `${decimalNumberValue * 100}%`;

return percentage;
}

console.log(convertToPercentage(0.8));
27 changes: 23 additions & 4 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,35 @@

// =============> write your prediction of the error here

function square(3) {
return num * num;
}
// function square(3) {
// return num * num;
// }

// =============> write the error message here
/*/Users/ike/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/2.js:8
function square(3) {
^
SyntaxError: Unexpected number
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
*/

// =============> explain this error message here
/*
- the error is a SyntaxError because we are passing the parameter 3 to the function and our program isn't expecting a number.
_ To fix this error, we need to pass the variable num as parameter to the function square.
*/

// Finally, correct the code to fix the problem

// =============> write your new code here
function square(num) {
return num * num;
}


console.log(square(3))
19 changes: 14 additions & 5 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
// Predict and explain first...

// =============> write your prediction here
/*
- The function multiply takes 2 parameters a and b and logging the value of a multiplied by b within the function but it's not returning the value.

function multiply(a, b) {
console.log(a * b);
}
*/
// function multiply(a, b) {
// console.log(a * b);
// }

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

// =============> write your explanation here

// - Line 9 will log the value to the console but line 12 will generate undefined because the value of a * b is not returned.
// Finally, correct the code to fix the problem
// =============> write your new code here

function multiply(a, b) {
return (a * b);
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
15 changes: 10 additions & 5 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// Predict and explain first...
// =============> write your prediction here
// - The function will print undefined as it's not returning anything.

function sum(a, b) {
return;
a + b;
}
// function sum(a, b) {
// return;
// a + b;
// }

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

// =============> write your explanation here
// Finally, correct the code to fix the problem
// =============> write your new code here
function sum(a, b) {
return a + b;;
}
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
27 changes: 20 additions & 7 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

// Predict the output of the following code:
// =============> Write your prediction here
// This function getLastDigit is trying to get the last digit of a number but will not work because it has no parameter

const num = 103;
// const num = 103;

function getLastDigit() {
return num.toString().slice(-1);
}
// function getLastDigit() {
// return num.toString().slice(-1);
// }

console.log(`The last digit of 42 is ${getLastDigit(42)}`);
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);

// Now run the code and compare the output to your prediction
// =============> write the output here
Expand All @@ -20,5 +21,17 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
// Finally, correct the code to fix the problem
// =============> write your new code here

const num = 103;

function getLastDigit(num) {
return num.toString().slice(-1);
}

console.log(`The last digit of 42 is ${getLastDigit(42)}`);
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem

/* This function getLastDigit is trying to get the last digit of a number but will not work because it has no parameter. It instead declares the variable globally and the function will reference it as argument when we call the function because it was declared globally. This will print 3 for each call
*/
8 changes: 7 additions & 1 deletion Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
let heightSquared = height * height;
let bmiInDecimals = weight/ heightSquared;
let bmi = bmiInDecimals.toFixed(1);
return bmi
}

// console.log(calculateBMI(102, 1.85));
10 changes: 10 additions & 0 deletions Sprint-2/3-mandatory-implement/2-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@
// You will need to come up with an appropriate name for the function
// Use the MDN string documentation to help you find a solution
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase

// create a function called upperSnakeCase that takes a string of 2 or more words as a parameter
//returns the string in upper snake case e.g "hello ike" = HELLO_IKE

function upperSnakeCase(str){
let capitalizedSnakeCase = str.toUpperCase().replaceAll(" ","_");
return capitalizedSnakeCase
}


24 changes: 24 additions & 0 deletions Sprint-2/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,27 @@
// You will need to declare a function called toPounds with an appropriately named parameter.

// You should call this function a number of times to check it works for different inputs

function toPound(penceDigits) {
//initialises a constant variable with the value penceDigits
const penceString = penceDigits;
// removes the last element from the string using subString()
const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);
//returns 399 because the targetLength 3 is equivalent to the length of the string. So no "0" padding will be added.
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
//removing the last 2 digit of 399
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);
// returns 99 given that the padding starts at end and it's length is 2.
const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
//returns the value of pound and pence. Appends the £ at the start.
return `£${pounds}.${pence}`;
}

15 changes: 11 additions & 4 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,39 @@ function pad(num) {
}

function formatTimeDisplay(seconds) {
const remainingSeconds = seconds % 60;
const totalMinutes = (seconds - remainingSeconds) / 60;
const remainingMinutes = totalMinutes % 60;
const totalHours = (totalMinutes - remainingMinutes) / 60;
const remainingSeconds = seconds % 60; //61 % 60 = 1
const totalMinutes = (seconds - remainingSeconds) / 60; //(61-1)/60 = 1
const remainingMinutes = totalMinutes % 60; //1 % 60 = 1
const totalHours = (totalMinutes - remainingMinutes) / 60; //(1 - 1)/60 = 0

return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
}

console.log(formatTimeDisplay(61));

// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
// to help you answer these questions

// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// pad will be called 3 times

// Call formatTimeDisplay with an input of 61, now answer the following:

// b) What is the value assigned to num when pad is called for the first time?
// =============> write your answer here
// The value is 0 because total hours is 0 i.e (1-1)/60 = 0

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// The return value is 00 because "0".padStart(2, "0") is "00"

// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
// =============> write your answer here
// the value is 1 because 61 % 60 = 1

// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
// =============> write your answer here
// The return value is 01 because the value assign to nun is 1. When pad is called, it adds 0 at the start of the num because the length of the string num is currently 1.
14 changes: 11 additions & 3 deletions Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
// read to the end, complete line 36, then pass your test here
if(angle < 90) return "Acute angle";
if(angle > 90 && angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
if(angle > 180 && angle < 360) return "Reflex angle";
}

// we're going to use this helper function to make our assertions easier to read
Expand Down Expand Up @@ -41,16 +45,20 @@ assertEquals(acute, "Acute angle");

// Case 3: Identify Obtuse Angles:
// When the angle is greater than 90 degrees and less than 180 degrees,
// if(angle > 90 && angle is < 180) return "Obtuse angle"
// Then the function should return "Obtuse angle"
const obtuse = getAngleType(120);
// ====> write your test here, and then add a line to pass the test in the function above

assertEquals(obtuse, "Obtuse angle")
// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"
// ====> write your test here, and then add a line to pass the test in the function above

const straight = getAngleType(180)
assertEquals(straight, "Straight angle")
// Case 5: Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"
// ====> write your test here, and then add a line to pass the test in the function above
// ====> write your test here, and then add a line to pass the test in the function above
const reflex = getAngleType(360)
assertEquals(reflex, "Reflex angle");
3 changes: 3 additions & 0 deletions Sprint-3/1-key-implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (numerator >= denominator) return false;
}

// here's our helper again
Expand Down Expand Up @@ -41,13 +42,15 @@ assertEquals(improperFraction, false);
// 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.
const negativeFraction = isProperFraction(-4, 7);
// ====> complete with your assertion
assertEquals(negativeFraction, 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.
const equalFraction = isProperFraction(3, 3);
// ====> complete with your assertion
assertEquals(equalFraction, false)

// Stretch:
// What other scenarios could you test for?
Loading