Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
51a060d
explaining line line 3
Ebrahim-Moqbel Feb 24, 2026
795be43
creating initials from a string
Ebrahim-Moqbel Feb 24, 2026
2b4173b
solved the exercises
Ebrahim-Moqbel Feb 25, 2026
c77e1c3
interpreting the programs
Ebrahim-Moqbel Feb 25, 2026
e829acf
explored console in the developer tools and answered some Qs
Ebrahim-Moqbel Feb 26, 2026
14fee9a
answered the exercises of the key errors and debug the mandatory file
Ebrahim-Moqbel Feb 26, 2026
d424070
solved the 3-mandatory implement file
Ebrahim-Moqbel Feb 27, 2026
2eaa851
solved the mandatory interpret
Ebrahim-Moqbel Feb 27, 2026
1c37d58
Deleted the changes of the sprint one file to meet the mata Data vali…
Ebrahim-Moqbel Feb 28, 2026
4d8de06
reviwing the content for updates and polishing my explanations
Ebrahim-Moqbel Jul 28, 2026
69791bc
revising and reviewing the content further expalining some of the rea…
Ebrahim-Moqbel Jul 28, 2026
97abaaa
revising and reviewing the content further expalining some of the rea…
Ebrahim-Moqbel Jul 28, 2026
3fcb050
Merge branch 'main' into acoursework/sprint-2
Ebrahim-Moqbel Jul 28, 2026
2efa343
explain the return value of using the function pad
Ebrahim-Moqbel Jul 28, 2026
4435e7f
commiting the changes
Ebrahim-Moqbel Jul 28, 2026
c234195
comitting changes to march the reviewer suggestions
Ebrahim-Moqbel Jul 29, 2026
599853f
answered and updated the explanation
Ebrahim-Moqbel Aug 21, 2026
a4f20f2
meeting the requirements of the raised suggestions
Ebrahim-Moqbel Aug 21, 2026
da4d7e7
updated the explanation to meet with function return
Ebrahim-Moqbel Aug 21, 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
33 changes: 26 additions & 7 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
// Predict and explain first...
// =============> write your prediction here
/*
I predict the function will throw a SyntaxError as the variable str has already been declared in the function parameter
function capitalise will capitalise the first letter with index 0
and will append the sliced string from index 1 which is the second letter
*/

// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
//call the function capitalise with a string input

// interpret the error message and figure out why an error is occurring :

/* syntax Error :identifier the variabel has already been declared.
As we can see the str variable has already been declared in the prameter of the function instead we just return the value */

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


// =============> write your explanation here
/* syntax Error :identifier the variabel has already been declared.
As we can see the str variable has already been declared in the prameter of the function instead we just return the value */

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

// =============> write your explanation here
// =============> write your new code here
}
console.log(capitalise("ebrahim"));
console.log(capitalise('salomi'));
27 changes: 19 additions & 8 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,29 @@
// Why will an error occur when this program runs?
// =============> write your prediction here

// Try playing computer with the example to work out what is going on
//1- The function is trying to declare the decimalNumber twice in the perameter and later as a new variable
//2-console.log() is printing a variable in the local scope where it can't be accessed as it is inside the function

function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;
// Try playing computer with the example to work out what is going on

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

console.log(decimalNumber);
// return percentage;
// }

// =============> write your explanation here
/* The variable decimal Number has already been declared in the parameter
and already is a local variable which can't be declared again causing a SyntaxError
As the decimalNumber inside the function we can't print it using the console.log() as it has no power to the local scope
instead we can delete the second declaration and just leave the parameter as an input for the user
Finally, correct the code to fix the problem */

// 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));
16 changes: 12 additions & 4 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@

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

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

// =============> write your prediction of the error here
//I predict the funciton will throw a SyntaxEror as the perametters sould be valid variables like names or identifiers with upholding to the variable naming convention and in this case a number found

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

// =============> write the error message here
//the Error is a syntax error: Unexpected number

// =============> explain this error message here
/* The function was givin a number as its perameter where in JS only allows varaible names and usnig a number causes a SyntaxError
Also, the function was returning num*num where num is undefined causing a syntax error
*/

// Finally, correct the code to fix the problem

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

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

console.log(square(25));
17 changes: 13 additions & 4 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
// This function would multiply the two arguments a and b whatever that is
// when we log the output we will get the string and the output of the function but because we are not returning an output we might run into an error

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
//The console.log() inside the funtion will print a*b but when we call the function will return 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)}`);

20 changes: 15 additions & 5 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
// Predict and explain first...
// =============> write your prediction here
// The function suppose to return the sum of the two variables but we will encounter an error as the code after return is unreachable.

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

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
// function sum(a, b) {
// return;
// a + b;
// }
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

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

// As we return nothing by closing the line with a semicolon hence a + b is not returned where we tell the computer to exit and go back to global scope and the computer will not be able to read the lines after that

// 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)}`);
35 changes: 28 additions & 7 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,44 @@

// Predict the output of the following code:
// =============> Write your prediction here
//getLastDigit will convert a number to a string
// However, since there is no parameter or local variable to the function we might run into an Error

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
// =============> write your explanation here
// As expected, the function has no parameters, so it relies on the global variable "num" as its only variable.
// Since there are no parameters defined, the function permanently uses the global variable instead.
// This means even if we pass arguments when calling the function, they will be ignored because there are no parameters to receive them.

// 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
/* the reason why getLastDigit isn't working properly is that it doesn't accept any arrguments where there isn't any perameters in its difination.
where it uses the golabal varaible 'num' decalred outside the funtion and already set to 103

The correct code includes a parameter 'num' in the difination this allows the function to accept the number passed to it when called*/
10 changes: 8 additions & 2 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@
// It should return their Body Mass Index to 1 decimal place

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


}

console.log(calculateBMI(70,1.7))
console.log(calculateBMI(72,1.7))
5 changes: 5 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,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(string) {
return string.toUpperCase().replaceAll(" ", "_");
}
console.log(toUpperSnakeCase("hello there"));
console.log(toUpperSnakeCase("lord of the rings"));
21 changes: 21 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,24 @@
// 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('987p'));
console.log(toPounds('909p'));
console.log(toPounds('345p'));
13 changes: 8 additions & 5 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@ function formatTimeDisplay(seconds) {
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
// =============> 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 first time pad was called with 61 the value is 00:01:01

// 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
// the last time, pad() is called with the remaining seconds which is value 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
// =============> 1
// the return value is "1" but as we are using pad would be adding a leading of "0" to become "01"
Loading