+
+
+
+
\ No newline at end of file
diff --git a/Sprint-1/prep/percentage.html b/Sprint-1/prep/percentage.html
new file mode 100644
index 000000000..065781e07
--- /dev/null
+++ b/Sprint-1/prep/percentage.html
@@ -0,0 +1,136 @@
+
+
+
+
+
+ Percentage Exercise
+
+
+
+
Percentage Exercise
+
+
+
Convert Decimal to Percentage
+
enter a decimal number and click the button to see the percentage:
+
+
+
+
+
+
+
Calculate the area and perimeter
+
enter the width and height to calculate the area and perimeter
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Sprint-1/prep/simpleExampleOfEventlistener.html b/Sprint-1/prep/simpleExampleOfEventlistener.html
new file mode 100644
index 000000000..741df24d5
--- /dev/null
+++ b/Sprint-1/prep/simpleExampleOfEventlistener.html
@@ -0,0 +1,94 @@
+
+
+
+
+
+
+ Simple Example of Event Listener
+
+
+
+
+
Simple Example of Event Listener
+click the button to see the event listener in action:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js
index 653d6f5a0..2a8c55d17 100644
--- a/Sprint-2/1-key-errors/0.js
+++ b/Sprint-2/1-key-errors/0.js
@@ -1,13 +1,20 @@
// Predict and explain first...
-// =============> write your prediction here
+// =============> this function get the argument and as string then first letter in capital and the rest of string in lower case;
// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
-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
+// the problem is in line 8, because we can not use the "str" twice, currently once we used as parameter and again as variable,
// =============> write your new code here
+
+function capitalise(str) {
+ return `${str[0].toUpperCase()}${str.slice(1)}`;
+
+}
+console.log(capitalise("hello world"));
diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js
index f2d56151f..7310592a3 100644
--- a/Sprint-2/1-key-errors/1.js
+++ b/Sprint-2/1-key-errors/1.js
@@ -2,19 +2,36 @@
// Why will an error occur when this program runs?
// =============> write your prediction here
-
+// the problem is in line 10, because we can not use the "decimalNumber" twice, currently once we used as parameter and again as variable,
+// this will cause an error "SyntaxError: Identifier 'decimalNumber' has already been declared"
// 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
-
+// by line 9 the computer we remember the name of the function and its parameter but still it doesn't do any thing.
+// by line 10 the computer will try to declare a new variable with the same name as the parameter of the function
+// and it will cause an error because we can not use the same name twice in the same scope. even if it accept it no matter what argument
+//we pass to the function it will always take the value of the variable that we declared inside the function.
+//line 11 the computer will try to calculate the percentage but it will not reach this line because of the error in line 10.
+// line 13 the computer will try to print the value of decimalNumber but it will not reach this line because of the error in line 10. but if reach
+// it will always print 0.5 no matter what argument we pass to the function.
+// in this case the error is "SyntaxError: Identifier 'decimalNumber' has already been declared" but if we fix it ,
+//then then console will give us the decimal number that we pass to the function in percentage format.
// 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(.45));
diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js
index aad57f7cf..6f03b2973 100644
--- a/Sprint-2/1-key-errors/2.js
+++ b/Sprint-2/1-key-errors/2.js
@@ -4,17 +4,31 @@
// this function should square any number but instead we're going to get an error
// =============> write your prediction of the error here
+// in javaScript function parameters should be variable names, but in line 10 we used a number "3" as parameter,
+// so the error will be "SyntaxError"
-function square(3) {
- return num * num;
-}
+// function square(3) {
+// return num * num;
+// }
// =============> write the error message here
+// function square(3) {
+// ^
+
+// SyntaxError: Unexpected number
// =============> explain this error message here
+// the problem is in line 10, because we can not use a number as parameter of the function, it should be variable name,
+// so the error is "SyntaxError: Unexpected number"
+
// Finally, correct the code to fix the problem
// =============> write your new code here
+function square(num) {
+ return num * num;
+}
+
+console.log(square(3));
diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js
index b27511b41..d6d1b4bc2 100644
--- a/Sprint-2/2-mandatory-debug/0.js
+++ b/Sprint-2/2-mandatory-debug/0.js
@@ -1,14 +1,31 @@
// Predict and explain first...
// =============> write your prediction here
+// in this code we have a function called multiply that takes two parameters a and b,
+//inside the function it will print the result of multiplying a and b,
+// but a and b are not defined, not in global scope nor local scope, so we will get error.
+// there is another console log statement that will print a string with the result of multiplying 10 and 32,
+// but the function multiply does not return any value, so the result will be undefined.
+// so the final output will be "The result of multiplying 10 and 32 is 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
+// it wasn't completely as I predicted, the first console log statement inside the function multiply did worked and
+// it printed 320, which means that the function parameters a and b took the values 10 and 32 from the function call multiply(10, 32).
+// but the second console log statement printed "The result of multiplying 10 and 32 is undefined" because the function multiply does not return any value,
+// so the result of multiplying 10 and 32 is undefined.
// Finally, correct the code to fix the problem
// =============> write your new code here
+// I will add a return statement to the function multiply that returns the result of multiplying a and b.
+
+function multiply(a, b) {
+ return (a * b);
+}
+
+console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
\ No newline at end of file
diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js
index 37cedfbcf..2c821413a 100644
--- a/Sprint-2/2-mandatory-debug/1.js
+++ b/Sprint-2/2-mandatory-debug/1.js
@@ -1,13 +1,27 @@
// Predict and explain first...
// =============> write your prediction here
+// in this code we have a function called sum that takes two parameters a and b,
+// inside the function there is a return statement followed by a; and then an expression a + b;
+// but in JavaScript, when a return statement is executed, the function exits immediately and any code after the return statement is not executed.
+// so the function will always return undefined because there is no value after the return statement.
+// so the final output will be "The sum of 10 and 32 is undefined"
-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
+
+// it behaved exactly as I predicted, the console log statement printed "The sum of 10 and 32 is undefined"
// Finally, correct the code to fix the problem
// =============> write your new code here
+// to correct the code we just need to remove the semicolon after the return statement.
+
+function sum(a, b) {
+ return a + b;
+}
+
+console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js
index 57d3f5dc3..f712ea0ce 100644
--- a/Sprint-2/2-mandatory-debug/2.js
+++ b/Sprint-2/2-mandatory-debug/2.js
@@ -2,23 +2,39 @@
// Predict the output of the following code:
// =============> Write your prediction here
+//the function has no parameter so I am not sure if it get the 42, 105 and 806 as input or it will always use the value of num which is 103,
+// but I know it change the number to string and get the last digit using slice method, because of the -1 index that means the last character.
+// 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
+// It happens because, as I predicted, the function always considers 103 as its argument
+
// 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
diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js
index 17b1cbde1..9a7dd332a 100644
--- a/Sprint-2/3-mandatory-implement/1-bmi.js
+++ b/Sprint-2/3-mandatory-implement/1-bmi.js
@@ -16,4 +16,7 @@
function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
-}
\ No newline at end of file
+ return (weight / (height * height)).toFixed(1);
+}
+console.log(calculateBMI(70, 1.73));
+console.assert(calculateBMI(80, 1.73) === '26.7');
\ No newline at end of file
diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js
index 5b0ef77ad..87b499474 100644
--- a/Sprint-2/3-mandatory-implement/2-cases.js
+++ b/Sprint-2/3-mandatory-implement/2-cases.js
@@ -14,3 +14,12 @@
// 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 convertToUpperSnakeCase(str) {
+ let upperCase= str.toUpperCase();
+ return upperCase.split(" ").join("_");
+
+}
+console.log(convertToUpperSnakeCase("hello there"));
+
+console.assert(convertToUpperSnakeCase("hello there") === "HELLO_THERE", "Test Case 1 Failed");
+console.assert(convertToUpperSnakeCase("lord of the rings") === "LORD_OF_THE_RINGS", "Test Case 2 Failed");
\ No newline at end of file
diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js
index 6265a1a70..ba7ef5daf 100644
--- a/Sprint-2/3-mandatory-implement/3-to-pounds.js
+++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js
@@ -4,3 +4,16 @@
// 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("9p"));
+console.log(toPounds("85p"));
+console.log(toPounds("1200p"));
+// it works for all the test cases
\ No newline at end of file
diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js
index 7c98eb0e8..10fd4102c 100644
--- a/Sprint-2/4-mandatory-interpret/time-format.js
+++ b/Sprint-2/4-mandatory-interpret/time-format.js
@@ -11,6 +11,9 @@ 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
@@ -18,17 +21,22 @@ function formatTimeDisplay(seconds) {
// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
+// it will be called 3 times, because in the return statement we called it 3 times, once for hours, once for minutes and once for 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 assigned to num is totalHours which is 0.
// c) What is the return value of pad is called for the first time?
// =============> write your answer here
-
+// it is 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
+ //The value assigned to num when pad is called for the last time is 1, because remainingSeconds = 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
+//The return value of pad(1) is "01".
+//That’s because inside pad, the number 1 becomes the string "1", and then padStart(2, "0") adds a leading zero to make it two digits.
\ No newline at end of file
diff --git a/Sprint-2/Prep/12hours.js b/Sprint-2/Prep/12hours.js
new file mode 100644
index 000000000..053754e4d
--- /dev/null
+++ b/Sprint-2/Prep/12hours.js
@@ -0,0 +1,27 @@
+function formatAs12HourClock(time) {
+ if (Number(time.slice(0, 2)) > 12) {
+ return `${Number(time.slice(0, 2)) - 12}:00 pm`;
+ }
+ return `${time} am`;
+}
+
+const currentOutput = formatAs12HourClock("08:00");
+const targetOutput = "08:00 am";
+console.assert(
+ currentOutput === targetOutput,
+ `current output: ${currentOutput}, target output: ${targetOutput}`
+);
+
+const currentOutput2 = formatAs12HourClock("23:00");
+const targetOutput2 = "11:00 pm";
+console.assert(
+ currentOutput2 === targetOutput2,
+ `current output: ${currentOutput2}, target output: ${targetOutput2}`
+);
+const currentOutput3 = formatAs12HourClock("00:00");
+const targetOutput3 = "12:00 am";
+console.assert(
+ currentOutput2 === targetOutput2,
+ `current output: ${currentOutput2}, target output: ${targetOutput2}`
+);
+console.log(currentOutput3,targetOutput3);
\ No newline at end of file
diff --git a/Sprint-2/Prep/elevator.js b/Sprint-2/Prep/elevator.js
new file mode 100644
index 000000000..e69de29bb