Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dc1ecca
made a prediction on what the error could be and gave value by calli…
MaharitB Sep 25, 2026
ff58b19
gave explanation on the error message and wrote a code to fix the error
MaharitB Sep 25, 2026
a09f7df
wrote the fixed code and made the code with the bag comment
MaharitB Sep 25, 2026
772f4ab
run prettier
MaharitB Sep 25, 2026
34272f8
add predict and explain about the code
MaharitB Sep 25, 2026
cdb17fe
Interpret the error message
MaharitB Sep 25, 2026
aa750f6
correct code 1.
MaharitB Sep 25, 2026
5816a40
correct code 2
MaharitB Sep 25, 2026
f51c24c
Predict and explain what the error might be
MaharitB Sep 25, 2026
83b4a7b
run the code by calling the vanction with no value and the error message
MaharitB Sep 25, 2026
22b0b87
Explain the error message
MaharitB Sep 25, 2026
71935b5
correcet code that fixed the error
MaharitB Sep 25, 2026
031eaf3
predit error and expplain outcome
MaharitB Sep 26, 2026
54e0afb
correct code for o.js 2-mandatory debug
MaharitB Sep 27, 2026
b4c7cf2
write a preditction and explain
MaharitB Sep 27, 2026
3923291
editted the prediction(wrote prediction and explanation in the same l…
MaharitB Sep 27, 2026
364a5e9
predicted and explained the error of the code
MaharitB Sep 27, 2026
96440cb
wrote the code again by fixing error
MaharitB Sep 27, 2026
fe28db6
made the first code and run and checked the newcode, displayed the ou…
MaharitB Sep 27, 2026
6a25d50
Wrote the code and tested
MaharitB Sep 27, 2026
dfbeb67
wrote the code foe UPPER_SNAKE_CASE
MaharitB Sep 27, 2026
92253f5
wrote the code and tested the code with different value
MaharitB Sep 27, 2026
3301df8
run the code and answered the questions
MaharitB Sep 27, 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
20 changes: 13 additions & 7 deletions Sprint-3/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// Predict and explain first...
// =============> write your prediction here
// on line 8, let declaring with name the same as the parameter

// 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)}`;
//It says syntax error Identifier 'str' has already been declared.
// function parameter and let which is inside the funtion can never
// be the same because both variables are in the same scope
// function capitalise(str) {
//let str = `${str[0].toUpperCase()}${str.slice(1)}`;
//return str;
//}
//console.log(capitalise("error")
//
function capitalise(firstLetter) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

correct use of function

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

// =============> write your explanation here
// =============> write your new code here
console.log(capitalise("error"));
31 changes: 28 additions & 3 deletions Sprint-3/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
// / to calculate the percentage it has used the value from
// convertToPercentage() function so there will be error because
// the variable name for the parameter and const is the same. and console.log is called
// to print decimalNumber which is not known outside the function
// instead of printing the retun value of the function.

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

Expand All @@ -14,7 +18,28 @@ function convertToPercentage(decimalNumber) {

console.log(decimalNumber);

// =============> write your explanation here
// the error was syntaxError it is stating decimalNumber has already been declared
//the parameter of the function convertToPercentage() and the const variable is the same

// Finally, correct the code to fix the problem
// =============> write your new code here
// There can be two ways to fix the problem
// 1. to change const variable and the name decimalNumber in line 15.
// but still need to call the function convertToPercentage() in the consol.log()

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

//2 .The second one is to call the function with value in it.
// and to keep the code as it is except change the const variable name/or delet
// the const numeral with its value because there is no poin of keeping it.
//
// function convertToPercentage(decimalNumber){
// const numeral = 0.5;
// const percentage = `${decimalNumber*100}%`;
// return percentage;
// }
// console.log(convertToPercentage());
22 changes: 13 additions & 9 deletions Sprint-3/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...

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

// =============> write your prediction of the error here
// =============> function square(), shouldn't give a value to it , we can only pass
// an argument when the function is called, with value in it which is called argument.

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

// =============> write the error message here
// =============> Unexpected number

// =============> explain this error message here
// =============> unexpected number in the function, there should be only parameter there but here
// number is assigned instead of the variable name

// Finally, correct the code to fix the problem

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


function square(num) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct use of square function defination

return num * num;
}
console.log(square(3));
10 changes: 7 additions & 3 deletions Sprint-3/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// Predict and explain first...

// =============> write your prediction here
// =============> there is no return,to return the value to the function call

function multiply(a, b) {
console.log(a * b);
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

// =============> write your explanation here
// =============> the error is it is not printing out the function call in line 9.
// and returning is as undefined.

// Finally, correct the code to fix the problem
// =============> write your new code here
// Functiion multiply(a,b){
// return a*b
// }
// console.log (`The result of multiplying 10 and 32 is ${multiply(10, 32)}`)
13 changes: 10 additions & 3 deletions Sprint-3/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Predict and explain first...
// =============> write your prediction here
// =============> return value is written before the expression.

function sum(a, b) {
return;
Expand All @@ -8,6 +8,13 @@ function sum(a, b) {

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

// =============> write your explanation here
// =============> when the expression evaluates a value it will
// need a return statment,but the return statment is before the expression
// which will result in undefined outcome because the function that is passing
// an argument is not receiving output of the expression.
// Finally, correct the code to fix the problem
// =============> write your new code here
//
// function sum(a, a){
// return a+b;
//}
// console.log(`the sum of 10 and 32 is ${sum(10,32)}`);
44 changes: 34 additions & 10 deletions Sprint-3/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here
// =============> I think the num variable can be accesed by the funtion getLastDigit()
// so it means it is not using the argument that is passed by the function.
// the output for the three of function calls will be 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
// The output is
// * 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 is the way it is because it was taking the num value
// from the variable num that has been declared and initialized outside the function.
// and const num has a global scope.if the function hasn't declared a variable num
// inisde the function it will use the gobaly declared and insialized variable num
// Finally, correct the code to fix the problem
// =============> write your new code here
// =============>function getLastDigit() {
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.
// yes it does tell the last digit of each number
// The last digit of 42 is 2
// The last digit of 105 is 5
// The last digit of 806 is 6
// Explain why getLastDigit is not working properly - correct the problem
6 changes: 6 additions & 0 deletions Sprint-3/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
return (weight / (height* height)).toString().slice(0,4);

}
console.log(`Your BMI is ${calculateBMI(79,1.73)} `);

//The out come is
// Your BMI is 26.3
6 changes: 6 additions & 0 deletions Sprint-3/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 upperSnakeCase(string){

return string.toUpperCase().replaceAll(" ", "_")
}
console.log(upperSnakeCase("lord of the Rings."));
16 changes: 16 additions & 0 deletions Sprint-3/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,19 @@
// 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){
let withOutP = penceString.substring( 0,penceString.length - 1);
let paddedPenceNumberString = withOutP.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("502p"));


//output for 4050p is £40.50
//output for 29p is £0.29
//output for 502 is £5.02
21 changes: 16 additions & 5 deletions Sprint-3/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,35 @@ 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 pad() will be called

// 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
// =============> 0 is the value assigned to num.

// c) What is the return value of pad when it is called for the first time?
// =============> write your answer here
// =============> 00 is the value of pad when it was called for the first time.

// 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 is the value of num when the pad is called for the last time. The last time pad is called is
// by by putting "remaining seconds" which is 1 in the function pad .

// 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
// =============> 01 is the return value of pad.when pad()is called with the value of num 1 the expression
// inside the pad function evaluates to a value 01. If we go through the code
// function pad(num) {
//let numString = num.toString();===> the value of numstring becomes "1"
//while (numString.length < 2) { ===> this line it is checking if numString.length< 2, numString.length is 1 in this line
//numString = "0" + numString; ===> in this line numString will be 01. and again will go to while again to check if
// } numString.length is <2 and it is not then pad() will return 01.
//
//
Loading