Skip to content

London | May-2025 | Khilola_Rustamova | Module Structuring and Testing Data | Sprint 2 #631

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 15 commits into
base: main
Choose a base branch
from
Open
12 changes: 12 additions & 0 deletions Sprint-2/1-key-errors/0.js

Choose a reason for hiding this comment

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

Most of the files are missing Predictions, where it's required for you to write your prediction first.

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,17 @@ function capitalise(str) {
return str;
}

//because str is already existing parameter we can not declare let str again.
// we can rename the str to fix the problem.


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

console.log(capitalise("khilola"));


// =============> write your explanation here
// =============> write your new code here
10 changes: 10 additions & 0 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ function convertToPercentage(decimalNumber) {
console.log(decimalNumber);

// =============> write your explanation here
// decimalNumber is already a function parameter, so it's already declared in the function's scope.



// Finally, correct the code to fix the problem
// =============> write your new code here
function convertToPercentage(decimalNumber) {
const percentage = `${decimalNumber * 100}%`;

return percentage;
}

console.log(50);
10 changes: 8 additions & 2 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@

// this function should square any number but instead we're going to get an error

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

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

// =============> write the error message here
Function square(3)

Choose a reason for hiding this comment

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

Can you review again the error message?


// =============> explain this error message here

// 3 is not approprate parametr name.
// num is not defined,
// Finally, correct the code to fix the problem

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

Choose a reason for hiding this comment

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

This code will look neater using proper syntax. E.g. space between num*num and ending the statement with ;

Also, the function is missing curly braces


console.log(square(3));


5 changes: 5 additions & 0 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

// 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)}`);
8 changes: 8 additions & 0 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ function sum(a, b) {
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

// =============> write your explanation here
//The return; statement ends the function immediately.
//The next line (a + b;) is never executed because it's after the return and on a new line.
// 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)}`);
14 changes: 13 additions & 1 deletion Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,23 @@ 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
// =============> write the output here
//every time we run it we will get same answer 3

// Explain why the output is the way it is
// =============> write your explanation here
//it will only use global num=103

// Finally, correct the code to fix the problem
// =============> write your new code here
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
14 changes: 13 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,16 @@

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
}


function calculateBMI(weight, height) {
const bmi = weight / (height * height); //calculates the BMI
return parseFloat(bmi.toFixed(1)); // to ensure the result is rounded to 1 decimal place.
}// parselFloat converts the result back to a number from string.


console.log(calculateBMI(70, 1.73));

//

7 changes: 7 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,10 @@
// 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


const greating = "Hello there"
console.log (greating.toUpperCase());

const heading = "lord of the rings"
console.log(heading.toUpperCase());

Choose a reason for hiding this comment

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

Can you move this implementation into a function?

22 changes: 22 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,25 @@
// 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 toPounds(penceString) {
const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");

const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");

return `£${pounds}.${pence}`;
}

// checking with different inputs

console.log(toPounds("399p")); // £3.99
console.log(toPounds("7p")); // £0.07
console.log(toPounds("62p")); // £0.62
console.log(toPounds("400p")); // £4.00
console.log(toPounds("3p")); // £0.03
5 changes: 5 additions & 0 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ function formatTimeDisplay(seconds) {

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// pad is going to be called 3 times. for hours, minutes and seconds

// 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
// 0 because 61 seconds is less then hours

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
//"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
// 1 last call as 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
//"01" because pad(1) - "1".padStart(2,"0")-"01"
14 changes: 13 additions & 1 deletion Sprint-2/5-stretch-extend/format-time.js

Choose a reason for hiding this comment

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

Could you review this again?

The idea here is to write tests for various input data and edge cases, as well as to fix any bugs you find.

The test cases are missing.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
if (hours > 12) {
return `${hours - 12}:00 pm`;
return `${hours - 12}:00 pm`; //This hardcodes :00, losing the original minutes from the time input.
//Even original minutes aren't 00 it will always return :00
}
return `${time} am`;
}
Expand All @@ -23,3 +24,14 @@ console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);

function formatAs12HourClock(time) {
const [hourStr, minute] = time.split(":");
const hours = Number(hourStr);

const isPM = hours >= 12;
const displayHour = hours % 12 === 0 ? 12 : hours % 12;
const suffix = isPM ? "pm" : "am";

return `${String(displayHour).padStart(2, "0")}:${minute} ${suffix}`;
}