Skip to content

Glasgow | May-2025 | Adiyah Farhan | Sprint-2 #515

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 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
6 changes: 2 additions & 4 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ console.log(decimalNumber);*/
// Finally, correct the code to fix the problem
// =============> write your new code here

const decimalNumber = 0.5;

function convertToPercentage() {
function convertToPercentage(decimalNumber) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: You could also keep the original global variable decimalNumber should you need to, even if it has the same name as the parameter. If you are interested in know why, you can look up "How JS resolve conflicting name".

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for this valuable information.

const percentage = `${decimalNumber * 100}%`;

return percentage;
}

result = convertToPercentage();
result = convertToPercentage(0.6);
console.log(result);
3 changes: 2 additions & 1 deletion Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ function calculateBMI(weight, height) {
const heightSquare = height * height;
const BMI = weight / heightSquare;
const scaledBMI = BMI.toFixed(1);
return scaledBMI;
return Number(scaledBMI);
}

result = calculateBMI(80, 1.89);
console.log(result);
//console.log(typeof calculateBMI());
6 changes: 3 additions & 3 deletions Sprint-2/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function convertToPounds(penceString) {
.padEnd(2, "0");

const convertAmount = "£" + pounds + "." + pence;
console.log(convertAmount);
return convertAmount;
}

convertToPounds("399p");
convertToPounds("450p");
let convertedAmount = convertToPounds("450p");
console.log(convertedAmount);
2 changes: 1 addition & 1 deletion Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function formatTimeDisplay(seconds) {
// 0

// c) What is the return value of pad is called for the first time?
// 00
// "00"

// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
// 1. num is assigned the value of remaining seconds.
Expand Down
18 changes: 18 additions & 0 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ function formatAs12HourClock(time) {
const minutes = time.slice(3, 5);
if (hours > 12) {
return `${hours - 12}:${minutes} pm`;
} else if (hours == 0) {
return `12:${minutes} am`;
} else if (hours == 12) {
return `${time} pm`;
}
return `${time} am`;
}
Expand All @@ -31,3 +35,17 @@ console.assert(
currentOutput3 === targetOutput3,
`current output: ${currentOutput3}, target output: ${targetOutput3}`
);

const currentOutput4 = formatAs12HourClock("00:59");
const targetOutput4 = "12:59 am";
console.assert(
currentOutput4 === targetOutput4,
`current output: ${currentOutput4}, target output: ${targetOutput4}`
);

const currentOutput5 = formatAs12HourClock("12:34");
const targetOutput5 = "12:34 pm";
console.assert(
currentOutput5 === targetOutput5,
`current output: ${currentOutput5}, target output: ${targetOutput5}`
);