Skip to content

WESTMIDLAND ITP-MAY-2025 AHMAD EHSAS Coursework/sprint-2 #630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ count = count + 1;

// Line 1 is a variable declaration, creating the count variable with an initial value of 0
// Describe what line 3 is doing, in particular focus on what = is doing
// line 3 increases the value of count by 1.
// the "=" operator assigns the result of "count + 1" back to the variable count.
9 changes: 7 additions & 2 deletions Sprint-2/1-key-errors/0.js

Choose a reason for hiding this comment

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

Could you also write your prediction here?

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ function capitalise(str) {
return str;
}

// =============> write your explanation here
// =============> write your new code here
// =============> write your explanation here: when i call the function capitalise with a string input, it shows an error because i am trying to redeclare the variable "str" inside the function, which is already defined as a parameter. this causes a syntax error and we can not redeclare a variable with the same name.
// =============> write your new code here: we can not use let str because str is already the function parameter.

function capitalise(str) {
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
9 changes: 7 additions & 2 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Predict and explain first...

// Why will an error occur when this program runs?
// =============> write your prediction here
// =============> write your prediction here: my prediction: The error will occur because i am trying to redeclare the variable "decimalNumber".//

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

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

console.log(decimalNumber);

// =============> write your explanation here
// =============> write your explanation here: // the error: identifier `decimalNumber` has already been declared. this error shows that identifier has already been declared and we can not redeclare it again.The identifier `decimalNumber` declared in parameter.//

// Finally, correct the code to fix the problem
// =============> write your new code here
// function convertTopercentage(decimalNumber) {
// const percentage = `${decimalNumber * 100}%`;
// return percentage;
// }
// console.log(convertTopercentge(0.5));//
10 changes: 7 additions & 3 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@

// 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: the error might be inside the function "the square number" or might be num is not identified.//

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

// =============> write the error message here
// =============> write the error message here: Uncaught syntaxError: Unexpected number.//

// =============> explain this error message here
// =============> explain this error message here: This error occurs because the function parameter is not defined correctly. Instead of passing a number directly, we should use a variable name. In this case, we can use "num" as the parameter name.

// Finally, correct the code to fix the problem


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


8 changes: 6 additions & 2 deletions Sprint-2/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
// =============> write your prediction here: the value of a and b is not defined in the function and the return statement is missing.//

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
// =============> write your explanation here: The code is running but it has technical issue. the multiply function logs the result but does not return it.We need to use return function to use the result inside the string.//

// 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)}`);
7 changes: 5 additions & 2 deletions Sprint-2/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
// =============> write your prediction here: The return function is not defined, so the function will not return the sum of a and b.

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

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

// =============> write your explanation here
// =============> write your explanation here: in the code above, the function Sum is not returning because the return function is not defined and it is written incorrectly. The return function should be written before the a + b values.//
// Finally, correct the code to fix the problem
// =============> write your new code here
// function sum(a, b) {
// return a + b;
// }
16 changes: 12 additions & 4 deletions Sprint-2/2-mandatory-debug/2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Predict and explain first...

// Predict the output of the following code:
// =============> Write your prediction here
// =============> Write your prediction here: the function const should write inside the call function.//

const num = 103;

Expand All @@ -14,11 +14,19 @@ 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
// =============> write the output here: The output is 3 for all three calls.
// Explain why the output is the way it is
// =============> write your explanation here
// =============> write your explanation here: The function getLastDigit is not taking any parameters, so it always uses the outer variable num, which is 103. That's why the output is always 3.
// Finally, correct the code to fix the problem
// =============> write your new code here
// =============> 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
13 changes: 11 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,14 @@
// 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
}
var bmi = weight / (height * height);
var bmis = bmi.toFixed(1);
return `Your bmi is ${bmis}`;

// return the BMI of someone based off their weight and height
}
console.log(calculateBMI(85, 1.75));
// based on the above code: My weight is 85 kg and my height is 1.75m.
// first i squared my height: 1.75 * 1.75 = 3.0625.
// then i divided my weight by the squared height: 85 / 3.0625= 27.8
// so my BMI is `27.8`.
12 changes: 12 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,15 @@
// 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 noP = penceString.slice(0, -1);
const padded = noP.padStart(3, "0");
const pounds = padded.slice(0, -2);
const pence = padded.slice(-2).padEnd(2, "0");
return `£${pounds}.${pence}`;
}
console.log(toPounds("5p")); // £0.05
console.log(toPounds("70p")); // £0.70
console.log(toPounds("399p")); // £3.99
console.log(toPounds("1000p")); // £10.00
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 @@ -17,18 +17,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: When formatTimeDisplay is called four times pad will be called, one for remainingSeconds, one for remainingMinutes, one for totalMinutes and one for totalHours.

// 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: When pad is called for thee first time, num will be assigned the value of 1, which is the value of remainingSeconds.

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// =============> write your answer here: The return value of pad when called for the first time will be `01` because it pads the number 1 with a leading zero to make it two digits.

// 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: When pad is called for the last time, num will be assigned the value of 0, which is the value of totalHours.

// 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
// =============> write your answer here: when pad is called for the last time, the return value will be `0` because it pads the number 0 with a leading zero to make it two digits.