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
60f2cf6
Add some lines of code to calculate the area of a rectangle
Iswanna Oct 4, 2025
909a41e
Add function to capitalize first letter of a name
Iswanna Oct 4, 2025
6b42d00
Compare the current output with the target output using the strict eq…
Iswanna Oct 9, 2025
4470330
Organize prep directory into sprint-1 and sprint-2 folders and move J…
Iswanna Oct 9, 2025
86552fe
Use the console.assert function in the code
Iswanna Oct 9, 2025
1f028f7
Define a function to convert argument to time with "am" and add basse…
Iswanna Oct 10, 2025
7993291
Predict the output of the provided function, explain the actual error…
Iswanna Oct 16, 2025
aca4398
Explain why the program throws an error, simulate execution to identi…
Iswanna Oct 16, 2025
a8d716b
Add code predictions, explanations, and corrections
Iswanna Oct 16, 2025
b509c65
Change the first letter in ActualOutput to lower case
Iswanna Oct 16, 2025
f08d00a
Predict program behavior and provide corrected code
Iswanna Oct 16, 2025
f4b2ba4
Improve phrasing in the prediction section for clarity
Iswanna Oct 16, 2025
09df5e9
Predict what the sum function will output, explain how the code works…
Iswanna Oct 16, 2025
b639581
Comment out the lines of code with the error
Iswanna Oct 16, 2025
f59d4fc
Explain each line of the multiply function
Iswanna Oct 16, 2025
ebaaadc
Predict and explain each function call’s output, then fix the code to…
Iswanna Oct 17, 2025
97e074f
Updatea function that takes two parameters to calculate the BMI
Iswanna Oct 17, 2025
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
22 changes: 19 additions & 3 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
// Predict and explain first...
// =============> write your prediction here
// Answer
// If I call the function capitalise with a string input, I predict that it will return an error because the variable str
// has already been declared as a paramter of the function so it can not be re-declared

// 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;
//}

// =============> write your explanation here
//Answer
// The error message "SyntaxError: Identifier 'str' has already been declared" means that the identifier "str" has been declared and so can not be re-declared.
// This error occured because the same variable name occurs as a function parameter and is then redeclared using a let assignment in a function body again.
// Redeclaring the same variable within the same function or block scope using let is not allowed in JavaScript.

// =============> write your new code here
// Answer
function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}

// =============> write your explanation here
// =============> write your new code here
let actualOutput = capitalise("welcome");
console.log(actualOutput);
46 changes: 40 additions & 6 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,53 @@

// Why will an error occur when this program runs?
// =============> write your prediction here
// Prediction
// An error will occur when the program runs because a variable cannot be redeclared.
// The parameter "decimalNumber" is already a declared variable, so it cannot be redeclared again using const decimalNumber = 0.5; inside the same function.


// 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
// Explanation
//function convertToPercentage(decimalNumber) {
//const decimalNumber = 0.5;
//const percentage = `${decimalNumber * 100}%`;

//return percentage;
//}

// When the script starts, JavaScript defines the function convertToPercentage, but it doesn’t run it yet.
// This means that nothing is executed inside the function; only the function itself is stored in memory.

// console.log(decimalNumber);
// At this point, JavaScript looks for a variable called decimalNumber in the current scope (the global scope), but none exists.
// We only declared decimalNumber as a parameter inside the function (which hasn’t been called yet).
// Result: Because decimalNumber isn’t defined globally, JavaScript will throw an error
// At this point, JavaScript looks for a variable called decimalNumber in the current scope (the global scope).
// But none exists — we only declared decimalNumber as a parameter inside the function (which hasn’t been called yet).
// Error message: "SyntaxError: Identifier 'decimalNumber' has already been declared"

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

decimalNumber = 0.5;
function convertToPercentage(decimalNumber) {

const percentage = `${decimalNumber * 100}%`;

return percentage;
}

const actualOutput = convertToPercentage(15);
console.log(actualOutput);
console.log(decimalNumber);
20 changes: 16 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,29 @@
// this function should square any number but instead we're going to get an error

// =============> write your prediction of the error here
// When the code is being read or parsed by Node, it will throw a syntax error because it cannot interpret the number 3 inside the parentheses.
// This is because a number (3) is not a valid parameter name in a function definition.

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

// =============> write the error message here
//function square(3) {
// return num * num;
//}

// =============> write the error message here
// SyntaxError: Unexpected number
// =============> explain this error message here
// This error message indicates that JavaScript only allows identifiers as parameters in a function definition.
// If a literal value (such as a number, string, or object) is used instead, a SyntaxError will be thrown.


// Finally, correct the code to fix the problem

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

const actualOutput = square(3);
console.log(actualOutput);


31 changes: 27 additions & 4 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
// Predict and explain first...

// =============> write your prediction here
// Answer
// If this program runs, I predict that the function will return undefined because it has no return statement.
// Also, the console.log inside the multiply function will print its output to the terminal.
// Lastly, because the function returns undefined, when ${multiply(10, 32)} is used inside a template literal inside the console.log function, it will print undefined in that position.

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
// Explanation
// function multiply(a, b) {}
// This expression defines a function named multiply.
// The function takes two parameters: a and b.

// console.log(a * b);
// This expression multipies a and b and prints the result in the terminal.
// There is no return statement, so the function implicitly returns undefined.

// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
// In this expression, multiply(10, 32) is called.
// Because the function returns undefined, the template literal becomes: "The result of multiplying 10 and 32 is undefined"
// That string is printed to the console.

// Finally, correct the code to fix the problem
// =============> write your new code here
function multiply(a, b) {
console.log(a * b);
return a * b;
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
43 changes: 38 additions & 5 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
// Predict and explain first...
// =============> write your prediction here
// Answer
// I predict that calling sum(10, 32) will return `undefined`.
// This is because the `return` statement has a semicolon immediately after it,
// so JavaScript interprets it as `return;` which evaluate to "undefined" when the function is called
// The expression `a + b` on the next line will never be executed.
// Therefore, any console.log using sum(10, 32) will display `undefined` in the output.

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
// Explanation
// function sum(a, b) {
// This declares a function named sum that takes two parameters: a and b.

// return;
// The return statement is immediately followed by a semicolon.
// This causes the function to exit immediately.
// Since nothing is returned explicitly, JavaScript returns undefined by default.

// a + b;
// This line never executes because the function has already exited at the `return;` line.

// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
// In this expression, sum(10, 32) is called.
// Because the function returns undefined, the template literal becomes: "The sum of 10 and 32 is undefined"
// That string is printed to the console.

// Finally, correct the code to fix the problem
// I will fix the error by placing the expression a + b on the same line as the return statement.
// Optionally, I can use parentheses around the expression, but this is not required.

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

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

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
34 changes: 27 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,43 @@

// Predict the output of the following code:
// =============> Write your prediction here
// Prediction
// When the function is called, I predict that the output will always be 3.
// This is because the variable 'num' is defined outside the function and is always 103.
// Therefore, regardless of the argument passed to getLastDigit, it will always return the last digit of 103, which is 3.

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
// Output
// 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
// Explanation
// The output will always be 3 because the function getLastDigit does not have a parameter so can not accept any arguments.

// Finally, correct the code to fix the problem
// =============> write your new code here
// New code
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
8 changes: 7 additions & 1 deletion Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@

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

let actualOutput = calculateBMI(70, 1.73);
console.log(actualOutput); // 23.4
13 changes: 13 additions & 0 deletions prep/sprint-1/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Write a function that will calculate the area of a rectangle
//given its width and height

let width = 3;
let height = 4;

function calculateArea(width , height) {
const area = width * height;
return area;
}

const result = calculateArea(3,4+8);
console.log(result);
11 changes: 11 additions & 0 deletions prep/sprint-1/example2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function capitaliseFirstLetter(name) {
return (name[0].toUpperCase() + name.substring(1));
}

function createGreeting(name) {
const result = capitaliseFirstLetter(name);
return `Welcome ${result}`;
}

const greeting = createGreeting("barath");
console.log(greeting);
25 changes: 25 additions & 0 deletions prep/sprint-2/assertions-exercise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// const calculation = 10 + 32;
// const result = 40;
// console.assert(calculation === result);

// function formatAs12HourClock() {}
// console.log(formatAs12HourClock())
// console.assert(formatAs12HourClock("08:00") === "08:00 am" , `current output: ${formatAs12HourClock("08:00")} , target output: 08:00 am`);

function formatAs12HourClock(time) {
return `${time} am`;
}

const currentOutput = formatAs12HourClock("08:00");
const targetOutput = "08:00 am";
console.assert(
currentOutput === targetOutput,
`current output: ${currentOutput}, target output: ${targetOutput}`
);

const currentOutput1 = formatAs12HourClock("23:00");
const targetOutput1 = "11:00 pm";
console.assert(
currentOutput === targetOutput,
`current output: ${currentOutput}, target output: ${targetOutput}`
);
Empty file.
5 changes: 5 additions & 0 deletions prep/sprint-2/comparing-values.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function formatAs12HourClock() {

}

console.log(formatAs12HourClock("08:00") === "08:00am")