Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
bd83096
predicted that there will be a syntaxError
Tobias-Amaechina Jun 25, 2026
c371756
called the function with arguement
Tobias-Amaechina Jun 25, 2026
cd270fb
interpreted the error message and suggested the fix
Tobias-Amaechina Jun 25, 2026
31f5daf
commented out the original code so I can write the new code to fix …
Tobias-Amaechina Jun 25, 2026
1d0572a
wrote a new code that fixed the syntaxErrot and console the called …
Tobias-Amaechina Jun 25, 2026
782cf84
Predicted why an error will occur when the programm is run
Tobias-Amaechina Jun 26, 2026
0292824
When the code was ran an error occured as preicted showing that the …
Tobias-Amaechina Jun 26, 2026
99357d3
the error was fixed by reassignment instead of redeclaring the vari…
Tobias-Amaechina Jun 26, 2026
bb4f078
Explained what the error messages were saying and the line where they…
Tobias-Amaechina Jun 26, 2026
2bca2a9
commented out the original program so I can write a new working code
Tobias-Amaechina Jun 26, 2026
83f2a2a
removed the Variable reassignment to allow any decimal arguement to …
Tobias-Amaechina Jun 26, 2026
5625879
commented out the original code
Tobias-Amaechina Jun 26, 2026
5e1b919
wrote a new code that worked
Tobias-Amaechina Jun 26, 2026
5cb01c7
gave my prediction of what the two console .log will print to the …
Tobias-Amaechina Jun 26, 2026
c6e3991
gave the explanation as to why the fist console.log inside the funct…
Tobias-Amaechina Jun 26, 2026
637daa2
commented out the original code to allow re-writing a new one
Tobias-Amaechina Jun 26, 2026
31c2ebd
wrote a new code that did not print undefined as a vaule
Tobias-Amaechina Jun 26, 2026
dee2a91
gave my prediction that the function when called will give undefined
Tobias-Amaechina Jun 26, 2026
5d0b10b
gave an explanation as to why the console.log method produced undefined
Tobias-Amaechina Jun 26, 2026
8e9bc16
added more context to the explantion -how semicolon ended the return…
Tobias-Amaechina Jun 26, 2026
1e18211
commented out the original code to aid re-writing a new one
Tobias-Amaechina Jun 26, 2026
3ced51b
wrote a new code that works
Tobias-Amaechina Jun 26, 2026
92b372e
Wrote my prediction with an explanations
Tobias-Amaechina Jun 26, 2026
d6f096c
Wrote the ouput when the code was ran and compare them with my predi…
Tobias-Amaechina Jun 26, 2026
14b44dc
Explained why the output 3 for the three different Arguements
Tobias-Amaechina Jun 26, 2026
b98f6b1
commented out the original code to allow for re-write of new code
Tobias-Amaechina Jun 26, 2026
609ccf6
Wrote the new code to fix the scope issue with the global variable
Tobias-Amaechina Jun 26, 2026
6c7e483
Explanation was given as to why the code did not work and how it wa…
Tobias-Amaechina Jun 26, 2026
47a68fd
Added the return statment to the function's body
Tobias-Amaechina Jun 27, 2026
4290aae
the function was called and console to the screen with the two argue…
Tobias-Amaechina Jun 27, 2026
251d837
wrote the function with an apprioprate name
Tobias-Amaechina Jun 27, 2026
760b0f9
used the programm in Sprint-1 and turn it into a resuable code by im…
Tobias-Amaechina Jun 27, 2026
7ed11f3
Answered how many number of times the pad was called
Tobias-Amaechina Jun 27, 2026
4f030b8
answere the question on the value assigned to pad when it's called f…
Tobias-Amaechina Jun 27, 2026
356bd08
add comment sign to my earlier answer
Tobias-Amaechina Jun 27, 2026
7fdc864
answere question on what is the return value of pad when called for …
Tobias-Amaechina Jun 27, 2026
cac50d0
Answered the question of assign value to num when pad was called t…
Tobias-Amaechina Jun 27, 2026
65d9d7f
Answered question on the returned value to pad when its called the la…
Tobias-Amaechina Jun 27, 2026
5ec6dee
reset the file to it's orinal state
Tobias-Amaechina Jun 28, 2026
cae676c
wrote an Assertion to test Mid-day , which failed
Tobias-Amaechina Jun 28, 2026
ee0dcaf
Wrote a code to fix the assertion
Tobias-Amaechina Jun 28, 2026
0241153
wrote an assertion to test for Midnight , and it failed as it curren…
Tobias-Amaechina Jun 28, 2026
e3bb58b
wrote the code and corrected the variable namet 'targetOutput to ta…
Tobias-Amaechina Jun 28, 2026
93705d4
removed the white space after the am in the current ouput for the mi…
Tobias-Amaechina Jun 28, 2026
5ac78f9
adding comment to explain the assetion already witten to test when t…
Tobias-Amaechina Jun 28, 2026
d8396ef
fixed the code with String method and padStart method
Tobias-Amaechina Jun 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
15 changes: 12 additions & 3 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
// Predict and explain first...
// =============> write your prediction here
// =============> write your prediction here /* there will be a syntax error because the variable str is being declared twice in the same scope. The first declaration is in the function parameter, and the second declaration is inside the function body. This will cause a conflict and result in an error. */

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

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

}
capitalise("Tobias");*/

// =============> write your explanation here
// =============> write your explanation here /* when the function `capitalise` is called with the argument "Tobias", it tries to declare a new variable `str` inside the function body using `let`. However, `str` is already declared as a parameter of the function. In JavaScript, you cannot declare a variable with the same name in the same scope, which leads to a syntax error and from the error message thus /home/tobi/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/0.js:8
/*let str = `${str[0].toUpperCase()}${str.slice(1)}`;SyntaxError: Identifier 'str' has already been declared it is pointing at line 8 as where the syntax error occurred so to fix the error the value on line 8 will need to be reassigned and not redeclared */
// =============> write your new code here
function capitalise(str) {
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;

}
console.log(capitalise("Tobias"));
26 changes: 22 additions & 4 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
// =============> write your prediction here. /* Error will occur when this program is run because a variable already declared inside the function parameter , was redeclared inside the function body. Also the console.log function is calling the variable decimalNumber which is not defined in the global scope. */

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

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

return percentage;
}

console.log(decimalNumber); */

// =============> write your explanation /* the first error SyntaxError pointed at line 9 as to where the error occurred and explained that the identifier-decimalNumber has already been declared. The second error ReferenceError pointed at line 15 as to where the error occurred and explained that the identifier-decimalNumber is not defined in the global scope. */
/* /home/tobi/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/1.js:9
const decimalNumber = 0.5;
^

SyntaxError: Identifier 'decimalNumber' has already been declared*/
/* /home/tobi/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/1.js:15
console.log(decimalNumber);
^

// =============> write your explanation here
ReferenceError: decimalNumber is not defined*/

// Finally, correct the code to fix the problem
// =============> write your new code here
function convertToPercentage(decimalNumber) {
// removed the variable reassignment so that function call will work with any argument passed to it.
const percentage = `${decimalNumber * 100}%`;

return percentage;
}

console.log(convertToPercentage(0.75));
16 changes: 10 additions & 6 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@

// Predict and explain first BEFORE you run any code...
// Predict and explain first BEFORE you run any code...we are going to get a SyntaxError because the function parameter is a number and not a variable name. The function parameter should be a variable name that can be used inside the function body.

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

// =============> write your prediction of the error here
// =============> write your prediction of the error here // SyntaxError: Unexpected number.

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

// =============> write the error message here
// =============> write the error message here /* /home/tobi/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/2.js:8 function square(3) { SyntaxError: Unexpected number*/

// =============> explain this error message here
// =============> explain this error message here/* this error is saying that something is wrong with the function parameter because it is a number and not a variable name. The function parameter should be a variable name that can be used inside the function body. the SyntaxError denote that the rule is violated, and pointed out that the number is unexpected at line 8 */

// Finally, correct the code to fix the problem

// =============> write your new code here
function square(num) {
return num*num;
}
square();


15 changes: 10 additions & 5 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// Predict and explain first...

// =============> write your prediction here

function multiply(a, b) {
// =============> write your prediction here// The code will print 320 and undefine secondly.
/*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
// =============> write your explanation here. /* The function multiply is called inside the console.log statement, but it does not return any value. Instead, it only logs the result of multiplying a and b to the console. Therefore, when the console.log statement is executed, it will print "The result of multiplying 10 and 32 is undefined" because the multiply function does not return anything. The first console.log inside the multiply function will print 320 to the console, but the second console.log will print 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)}`);
15 changes: 10 additions & 5 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// Predict and explain first...
// =============> write your prediction here

function sum(a, b) {
// =============> write your prediction here // will print undefined.
/*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.// The code will print undefined because the function sum does not return any value. Instead, it has a return statement with no value, because the semicolon ended the return statement which means it will return undefined by default. The second line of the function, a + b, is never executed because the return statement ends the function execution before it can be reached.

// =============> write your explanation here
// 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)}`);
22 changes: 16 additions & 6 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here
// =============> Write your prediction here./* The output will be 3 because the function getLastDigit is not using the argument passed to it, instead it is using the global variable num which is set to 103. Therefore, the last digit of 103 is 3 and that is what will be printed for all three console.log statements.*/

const num = 103;
/*const num = 103;

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 806 is ${getLastDigit(806)}`);*/

// Now run the code and compare the output to your prediction
// =============> write the output here
// =============> write the output here// The out put is 3 for the three console.log calls as predicted
// Explain why the output is the way it is
// =============> write your explanation here
// =============> write your explanation here. /* The reason is because the function getLastDigit is not using the argument passed to it, instead it is using the global variable num which is set to 103. Therefore, the last digit of 103 is 3 and that is what will be printed for all three console.log statements.*/
// 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
// Explain why getLastDigit is not working properly - correct the problem// The variable num was a global variable , that is is why it was not working becasue it was declared outside of the function and was fixed by declaring it inside the function as a parameter .
4 changes: 3 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,7 @@
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
return`The BMI of someone with a weight of ${weight}kg and a height of ${height}m is ${(weight / (height * height)).toFixed(1)}`;
// return the BMI of someone based off their weight and height
}
}
console.log(calculateBMI(70, 1.73)); // should return 23.4
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 convertToUpperSnakeCase(inputString) {
return inputString.replace(/\s+/g,'_').toUpperCase();
}
console.log(convertToUpperSnakeCase("there is fire on the montain"));
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("30p"));
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 @@ -21,18 +21,18 @@ function formatTimeDisplay(seconds) {
// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// =============> write your answer here// three 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
// =============> write your answer here //0.

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// =============> 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
// =============> write your answer here// 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
// =============> write your answer here// "01"
31 changes: 30 additions & 1 deletion Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
if (hours > 12) {
return `${hours - 12}:00 pm`;
return `${String(hours - 12).padStart(2,"0")}:00 pm`;
}
if (hours===12){
return `${hours}:00 pm`;
}
if (hours===0){
return `${12}:00 am`;
}
return `${time} am`;
}

Expand All @@ -23,3 +29,26 @@ console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);
// testing for noon @ "12:00"
const currentOutput3 = formatAs12HourClock("12:00");
const targetOutput3 = "12:00 pm";
console.assert(
currentOutput3 === targetOutput3,
`current output: ${currentOutput3}, target output: ${targetOutput3}`
);
//Testing for Midnight
const currentOutput4 = formatAs12HourClock("00:00");
const targetOutput4 = "12:00 am";
console.assert(
currentOutput4 === targetOutput4,
`current output: ${currentOutput4}, target output: ${targetOutput4}`
);
// Testing for leading zeros

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

Loading