Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
f18f2af
in key errors 1.js explained the predicated errors and explained the …
Mona-Eltantawy Mar 4, 2026
e3e39a8
I added my predication and explaiened that an error will occur becaus…
Mona-Eltantawy Mar 4, 2026
e11ca35
predicted the the program will not work because the function will not…
Mona-Eltantawy Mar 4, 2026
89c0e11
explained that th function sum will not return any value because the …
Mona-Eltantawy Mar 4, 2026
a23c098
explained my predaction and changed the code by adding 'num' as a par…
Mona-Eltantawy Mar 5, 2026
58ecfb8
I implemented a function that calculates the BMI based on weight and …
Mona-Eltantawy Mar 6, 2026
7bc4f5d
I Implemented a function that replace the spaces in a string with an …
Mona-Eltantawy Mar 7, 2026
2e5854e
I declared a function called toPounds with a paramater called pencStr…
Mona-Eltantawy Mar 7, 2026
9d762f3
I answered the quesitions interpreting the code format.
Mona-Eltantawy Mar 8, 2026
1d7c01b
reedited the answers
Mona-Eltantawy Mar 8, 2026
6fe47f8
I added my prediction
Mona-Eltantawy Mar 8, 2026
956c1b0
re-edited the answers.
Mona-Eltantawy Mar 8, 2026
9027d5d
I prediacted that the error aill cbe because of the double declaratio…
Mona-Eltantawy Mar 8, 2026
86b563c
fixed the explaination sentence
Mona-Eltantawy Mar 18, 2026
eaa7a5d
reedited the explaination for fixing the issue.
Mona-Eltantawy Mar 18, 2026
e7a4817
I fixed the expected output value to be a number not a string by conv…
Mona-Eltantawy Mar 18, 2026
0235402
reformatted the file
Mona-Eltantawy Mar 18, 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
13 changes: 10 additions & 3 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Predict and explain first...
// =============> write your prediction here

// =============>
I predicte that the error will be that the variable str is already declared in the function.
// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring

Expand All @@ -9,5 +9,12 @@ function capitalise(str) {
return str;
}

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

// =============> write your explanation here
when I run the program it give an error message that the identifier str has already been declared. this is because the variable str is declared twice in the function capitalise and in the variable let str.
to fix this we can change the variable name of the let str to newStr and this will fix the issue.
// =============> write your new code here
function capitalise(str) {
let newStr = `${str[0].toUpperCase()}${str.slice(1)}`;
return newStr;
}
17 changes: 15 additions & 2 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
=============> write your prediction here: the error will occur because the variable decimslNumber gevine a value of 0.5
with a const declaration and this will make an error if the brograme given a diffrent value for the decimalNumber.

// Try playing computer with the example to work out what is going on

Expand All @@ -14,7 +15,19 @@ function convertToPercentage(decimalNumber) {

console.log(decimalNumber);

// =============> write your explanation here
// =============> write your explanation here
when the program run it give a SyntaxError: Identifier 'decimalNumber' has already been declared. This is because the variable decimalNumber is declared twice in the function
convertToPercentage.
Also using the function name decimalNumber with the console.log function will give an error because the function name should be a prober name not a Number.
to fix this error we can remove the const variable declaration of decimalNumber from the function and use the function name
'ConvertToPercentage' to recall the function and pass the value of the decimalNumber declaration
Comment on lines +19 to +23
Copy link
Contributor

Choose a reason for hiding this comment

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

Should you need to keep them as comment (so Prettier won't identify them as invalid code), you can add // at the start of each line.


// 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(0.5));
23 changes: 19 additions & 4 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@
// this function should square any number but instead we're going to get an error

// =============> write your prediction of the error here
the error will occur because the paramater of the function is not a valid variable name as it is a number.
also the variable num is not declared in the function and this will give an error when the program run because the function will not know what the value of the num is.

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

// =============> write the error message here
// =============> write the error message here
function square(3) {
^

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

// Finally, correct the code to fix the problem
// =============> explain this error message here it means that the paramater of the function is an unexpected number (3) and this is not a valid variable number.
I deleted the paramater of the function and run the programe and I get this error:
/box/index.js:2
return num * num;
^

// =============> write your new code here
ReferenceError: num is not defined


// Finally, correct the code to fix the problem
change the function to this: function square(num)
// =============> write your new code here
function square(num) {
return num * num;
}
console.log(square(3));
14 changes: 14 additions & 0 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Predict and explain first...

// =============> write your prediction here
I prediact that the error will occur because the function multiply does not return any value and this will make the console.log function to print undefined instead.


function multiply(a, b) {
console.log(a * b);
Expand All @@ -9,6 +11,18 @@ function multiply(a, b) {
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

// =============> write your explanation here
when the program run it give this output:

320
The result of multiplying 10 and 32 is undefined

320: the out put for the console.log inside the function

to fix this issue 'return' function should be used rather than 'console.log'
// 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)}`);
11 changes: 11 additions & 0 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Predict and explain first...
// =============> write your prediction here
I predicted that the function will not return the correct result because the return statment is not correctly declared.

function sum(a, b) {
return;
Expand All @@ -9,5 +10,15 @@ function sum(a, b) {
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

// =============> write your explanation here
when I run the program it give this output:
The sum of 10 and 32 is undefined

the output is undefiened because the function sum does not return any value.
to fix this error we need to change the return statement to return a + b instead of just return.

// 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)}`);
21 changes: 18 additions & 3 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// Predict the output of the following code:
// =============> Write your prediction here
I predict that because the num variable has been given a constant value, the program will give undefiened when the getLastDigt function called after.


const num = 103;

Expand All @@ -14,11 +16,24 @@ 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
// =============> write your explanation here
the output give 3 which is the last digit for the constant value declared to the num
because the function getLastDigit doesn't have the num as a paramater to accept it when we call it with the console.log function.
// 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
because it hasn't been gevine a paramater when it declared but when the num added as a paramater the program give the xpeacted outputs.
7 changes: 6 additions & 1 deletion Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
let BMI = weight / (height ** 2);
return Number(BMI.toFixed(1));
}

console.log(calculateBMI(80, 1.7));

// return the BMI of someone based off their weight and height
}
6 changes: 6 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,9 @@
// 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(str) {
return str.toUpperCase().replace(/ /g, '_')
}

console.log(toUpperSnakeCase ('hello there'));
20 changes: 20 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,23 @@
// 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(`£${pounds}.${pence}`);
10 changes: 5 additions & 5 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ function formatTimeDisplay(seconds) {
// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
Three times, once for the 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
The value assighned to num when the pad function called for the first time is 0, because the total hours is 0.

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
the return value of pad when it is called for the first time is '00' because the pad function add a '0' to the left of the num to make it 2 characters long. AS the num is 0 the return value is also ' 0'.

// 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 assighned to num when the pad function is called for the last time is 1 , because the remaining seconds is 1, as 61 seconds os equal to 1 minute and 1 second.

// 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 of pad when it is called for the last time is '01' because the pad function adds a '0' to the left of the num to make it 2 characters long. As the num is 1, the return value is '01'.
Loading