Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3bdfb60
Convert price strings to numbers before calculating
abmhts Sep 16, 2026
15e3b83
explaining error msg and fix the code
abmhts Sep 21, 2026
a44bb25
Explaining the error, prediction, and fix
abmhts Sep 21, 2026
c5a6226
fix function square code error
abmhts Sep 21, 2026
052c090
Added return statement to fix the error
abmhts Sep 21, 2026
d6eb93e
fix return statement
abmhts Sep 21, 2026
5afd460
BMI calculation code
abmhts Sep 22, 2026
a379651
fix of get last digit function error
abmhts Sep 22, 2026
e9fda63
convert to UPPER_SNAKE_CASE
abmhts Sep 22, 2026
f0201dd
added function called toPounds
abmhts Sep 23, 2026
c4470d9
time-format
abmhts Sep 23, 2026
add8d2e
Delete Sprint-2/3-mandatory-interpret/1-percentage-change.js
abmhts Sep 24, 2026
73113c5
Revert "Delete Sprint-2/3-mandatory-interpret/1-percentage-change.js"
abmhts Sep 24, 2026
fc9a860
Remove accidentally added file
abmhts Sep 24, 2026
6501234
Restore Sprint-2 file
abmhts Sep 24, 2026
65e5b19
Update- explaining the error, prediction, and fix
abmhts Sep 26, 2026
1b143ad
update - explaining error msg and fix the code
abmhts Sep 28, 2026
2583b44
Update 2- explaining error msg and fix the code
abmhts Sep 28, 2026
b124f10
update 2- Explaining the error, prediction, and fix
abmhts Sep 28, 2026
286c2a2
update
abmhts Sep 28, 2026
ff0eee9
update - fix function square code error
abmhts Sep 28, 2026
62e622c
Update - convert to UPPER_SNAKE_CASE
abmhts Sep 28, 2026
60be8e2
Remove Prettier changes from 5-stretch exercise
abmhts Sep 28, 2026
862d481
Applied Prettier
abmhts Sep 28, 2026
a4a378f
Merge branch 'coursework/sprint-3' of https://github.com/abmhts/Modul…
abmhts Sep 28, 2026
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
16 changes: 11 additions & 5 deletions Sprint-3/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// Predict and explain first...
// =============> write your prediction here

//- we expect a syntaxerror because "str" is already declared as function parameter and again as a variable within the same function scope.
// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
//"Error: SyntaxError: Identifier 'str' has already been declared" why: because "str" declared twice.

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
// Instead of storing the formatted string in a new variable and then returning it, I return the expression directly since the variable was only used once.
// =============> write your new code here
function capitalise(str) {
return `${str[0].toUpperCase()}${str.slice(1)}`;
}
console.log(capitalise("abakar"));
25 changes: 17 additions & 8 deletions Sprint-3/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
// Predict and explain first...

// Why will an error occur when this program runs?
//- variable name "decimalNumber" declared twice in the same function. one as function parameter and again as a const in the same function.
// =============> write your prediction here

//- SyntaxError because "decimalNumber" declared twice.
// 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
// I removed the separate decimalNumber variable because the function already accepts decimalNumber as a parameter. I can now pass a number directly when calling the function, such as convertToPercentage(7). The function multiplies the value by 100 and appends % to return the percentage.

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

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

return percentage;
}

console.log(convertToPercentage(7));
17 changes: 11 additions & 6 deletions Sprint-3/1-key-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@

// Predict and explain first BEFORE you run any code...

// this function should square any number but instead we're going to get an error
//we are giving a value for the input instead of name that can hold different values.

// =============> write your prediction of the error here
//syntaxerror related to the function input "(3)"

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

// =============> write the error message here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This answer is still empty. Your prediction on line 8 says SyntaxError. Was that right? Write the error name here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

updated the error message.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's the one. Fixed.


// SyntaxError: Unexpected number
// =============> explain this error message here

// we gave a placeholder for the function instead of value that can't be changed.
// Finally, correct the code to fix the problem

// =============> write your new code here

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

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

// =============> write your prediction here
//- "a and b" are defined as parameters and receive 10 and 32. The function calculates and logs 320, but it doesn't return the value. Because there is no return, the function call evaluates to undefined.

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
//- Added a return statement so the function returns the result to the function call. The console.log() is just printing 320 and function doesn't give 320 back and thats why "${multiply(10, 32)}" gets undefined.

// 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)}`);
18 changes: 13 additions & 5 deletions Sprint-3/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
// Predict and explain first...
// =============> write your prediction here
//- return statement in this case stops before it can do the sum of a + b.

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
//- added a + b to return so function returns the sum.
// 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)}`);
29 changes: 22 additions & 7 deletions Sprint-3/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,38 @@

// Predict the output of the following code:
// =============> Write your prediction here
//-getting the last digit of 103

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
//-The last digit of 42 is 3
//-The last digit of 105 is 3
//-The last digit of 806 is 3

// Explain why the output is the way it is
// -Every time the function calls 103
// =============> write your explanation here
// Finally, correct the code to fix the problem
// =============> write your new code here

// This program should tell the user the last digit of each number.
// Explain why getLastDigit is not working properly - correct the problem
//-I removed the unnecessary const num = 103 because the function already receives num as a parameter.
//-The function calculates something and returns it then console.log outside receives that returned value and prints it.

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)}`);
7 changes: 7 additions & 0 deletions Sprint-3/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@
// It should return a string of their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
const bmi = weight / (height * height);
return bmi.toFixed(1);

// return the BMI of someone based off their weight and height
}

console.log(
`Your BMI is ${calculateBMI(70, 1.73)}, based on your weight and height`,
);
5 changes: 5 additions & 0 deletions Sprint-3/3-mandatory-implement/2-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@
// 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

function toUpperSnakeCase(sentence) {
return sentence.toUpperCase().replaceAll(" ", "_");
}
console.log(toUpperSnakeCase("welcome to Chad"));
22 changes: 22 additions & 0 deletions Sprint-3/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}`;
}

console.log(toPounds("399p"));
console.log(toPounds("4000p"));
console.log(toPounds("39p"));
console.log(toPounds("3p"));
11 changes: 6 additions & 5 deletions Sprint-3/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ function formatTimeDisplay(seconds) {

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

console.log(formatTimeDisplay());
// 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

//- 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
//- 0

// c) What is the return value of pad when it 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, remainingSeconds is 1 because 61 % 60 = 1. The last call is pad(remainingSeconds) so pad(1) makes num = 1.

// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
// =============> write your answer here
//- "01" , num.toString() changes 1 into "1". Since "1" has only 1 character, the while loop adds "0" in front, making "01".
Loading