Skip to content

Module-Structuring-and-Testing-Data | Sprint-1 #528

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 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
82cec5d
update 1-count.js
nurzatpro Jun 8, 2025
6467880
update 2-initials
nurzatpro Jun 10, 2025
e6e9e18
update 2-mandatory-errors
nurzatpro Jun 10, 2025
0a92387
update 1js
nurzatpro Jun 10, 2025
ebbab63
update 3js
nurzatpro Jun 11, 2025
57c9692
update 1-percentage
nurzatpro Jun 11, 2025
e13f3e7
update sprint 1/2-mandatory-errors/4.js
nurzatpro Jun 11, 2025
cb7e0cf
update 2-initials.js
nurzatpro Jun 11, 2025
cac529e
update 3-paths.js
nurzatpro Jun 11, 2025
325d551
update 4-random.js
nurzatpro Jun 11, 2025
ec31455
update 3.js
nurzatpro Jun 11, 2025
18243e2
update 1-percentage-change-change.js
nurzatpro Jun 11, 2025
d580b92
update 2-time-format.js
nurzatpro Jun 11, 2025
a9b1745
update 3-to-pounds.js
nurzatpro Jun 12, 2025
f506dd3
1-count.js
nurzatpro Jun 21, 2025
652a66b
update 1.js
nurzatpro Jun 21, 2025
d0bb7dc
update 2.js
nurzatpro Jun 21, 2025
0cbc5ad
update 4.js
nurzatpro Jun 21, 2025
5362c2f
update 1-percentage-change.js
nurzatpro Jun 21, 2025
5914b8a
update time-format.js
nurzatpro Jun 21, 2025
180d914
update chrome.md
nurzatpro Jun 21, 2025
e99ba2d
update objects.md
nurzatpro Jun 21, 2025
bce7a36
Fix variable redeclaration error in capitalize function
nurzatpro Jun 25, 2025
b4b63e6
Fix SyntaxError in capitalize by removing str variable
nurzatpro Jun 25, 2025
b03d5c1
Fix the parameter of the function and output in the terminal
nurzatpro Jun 25, 2025
46e7933
fix the undefined value printed to the output
nurzatpro Jun 25, 2025
36e0def
fix the returning value
nurzatpro Jun 25, 2025
2d81ea8
fixing the function by defining parameter
nurzatpro Jun 26, 2025
624683e
BMI
nurzatpro Jun 26, 2025
be9bde8
Upper_snake_case
nurzatpro Jun 26, 2025
8a282aa
price in pounds
nurzatpro Jun 26, 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
4 changes: 4 additions & 0 deletions Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
let count = 0;

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


///answer line3 is a statement that increases count by 1. the =operator reassigns the result of count +1 back to the count variable
4 changes: 4 additions & 0 deletions Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ let initials = ``;

// https://www.google.com/search?q=get+first+character+of+string+mdn

// Get the first character of each name using [0]
let initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`;

console.log(initials); // Output: CKJ
9 changes: 8 additions & 1 deletion Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ console.log(`The base part of ${filePath} is ${base}`);
const dir = ;
const ext = ;

Choose a reason for hiding this comment

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

Be careful about reassigning variables - you've reused the dir and ext constants here

// https://www.google.com/search?q=slice+mdn
// https://www.google.com/search?q=slice+mdn

const dir = filePath.slice(0, lastSlashIndex);
console.log(`The dir part of ${filePath} is ${dir}`);

const lastDotIndex = base.lastIndexOf(".");
const ext = base.slice(lastDotIndex);
console.log(`The ext part of ${base} is ${ext}`);
9 changes: 9 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
// Try breaking down the expression and using documentation to explain what it means
// It will help to think about the order in which expressions are evaluated
// Try logging the value of num and running the program several times to build an idea of what the program is doing
// 1. Math.random() generates a decimal between 0 (inclusive) and 1 (exclusive)
// 2. Multiply by (maximum - minimum + 1) to scale to the desired range size
// 3. Math.floor() rounds down to get an integer from 0 up to range size minus 1
// 4. Adding minimum shifts the range so the lowest number is minimum, not zero
const num =
Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;

// Result: num is a random integer between minimum and maximum, inclusive
console.log(num);
7 changes: 6 additions & 1 deletion Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
This is just an instruction for the first activity - but it is just for human consumption
We don't want the computer to run these 2 lines - how can we solve this problem?
We don't want the computer to run these 2 lines - how can we solve this problem?

we use // at the beginning of the line
we wrap it with /**/ if it spans multiple

Comments are ignored by the JavaScript engine — they're only for humans to read, like notes or documentation.
11 changes: 11 additions & 0 deletions Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,14 @@

const age = 33;
age = age + 1;
//

// trying to create an age variable and then reassign the value by 1

let age = 33; //use 'let' instead 'const' that needs to be reassigned
age = age + 1;

console.log(age); //log the updated age value

//output:34

11 changes: 8 additions & 3 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?

// Currently trying to print the string "I was born in Bolton' but it is not working...
// What is the error?
//
console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";

// here we first declare cityOfBirth before using it to avoid error

//
"
11 changes: 11 additions & 0 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ const last4Digits = cardNumber.slice(-4);
// Then run the code and see what error it gives.
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
// Then try updating the expression last4Digits is assigned to, in order to get the correct value


//It will throw an error because cardNumber is a number, not a string — and .slice() is a method for strings and arrays, not numbers.

const cardNumber = 4533787178994213;
//convert number to string before using slice
const last4Digits = cardNumber.toString().slice(-4);
//log the last 4 digits
console.log(last4Digits);

//outcome 4213
19 changes: 18 additions & 1 deletion Sprint-1/2-mandatory-errors/4.js

Choose a reason for hiding this comment

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

can you explain the change you made here?

Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";



//output the values



console.log("Clock time in 12h format:", clockTime_12Hour);


console.log("Clock time in 24h format:",clockTime_24Hour);






33 changes: 33 additions & 0 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js

Choose a reason for hiding this comment

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

Good answer, I think you mixed up question d) with e) and are missing an answer. Could you identify the variable declarations?

Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,36 @@ console.log(`The percentage change is ${percentageChange}`);
// d) Identify all the lines that are variable declarations

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?

// answers:
// a) There are 5 function calls in this file. The lines where the function calls are made are:
// 1. carPrice.replaceAll(",", "") on line 4
// 2. Number(carPrice.replaceAll(",", "")) on line 4
// 3. priceAfterOneYear.replaceAll(",", "") on line 5
// 4. Number(priceAfterOneYear.replaceAll(",", "")) on line 5
// 5. console.log(`The percentage change is ${percentageChange}`) on line 8


console.log(...)

b)This line has a syntax error: there's an extra quote in replaceAll("," "")
It should be: replaceAll(",", "")

c) carPrice = Number(carPrice.replaceAll(",", ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
These 2 lines are reassignments — the values are being updated after declaration.

d)This is a nested expression that does two things:

carPrice.replaceAll(",", ""):

Replaces all commas with empty strings.

Example: "10,000" → "10000" (makes it usable as a number)

Number(...):

Converts the resulting string "10000" into the actual number 10000



32 changes: 32 additions & 0 deletions Sprint-1/3-mandatory-interpret/2-time-format.js

Choose a reason for hiding this comment

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

Good answers here

Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,52 @@ const totalMinutes = (movieLength - remainingSeconds) / 60;
const remainingMinutes = totalMinutes % 60;
const totalHours = (totalMinutes - remainingMinutes) / 60;

// Rename result to formattedTime for clarity

const formattedTime = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
console.log(formattedTime);

const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
console.log(result);

// For the piece of code above, read the code and then answer the following questions

// a) How many variable declarations are there in this program?

// There are 6 variable declarations:
// movieLength, [line 1]
// remainingSeconds, [line 3]
// totalMinutes, [line 4]
// remainingMinutes, [line 6]
// totalHours, [line 7]
// result. [line 9]

// b) How many function calls are there?

// There is 1 function call:
// console.log()

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

// The % operator is the remainder operator.
// movieLength % 60 gives the remainder after dividing movieLength by 60,
// which represents the leftover seconds after counting full minutes.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

// totalMinutes calculates how many whole minutes are in movieLength by
// subtracting leftover seconds and dividing the remainder by 60.

// e) What do you think the variable result represents? Can you think of a better name for this variable?

// Result is the movie length formatted as "hours:minutes:seconds".
// A better name could be formattedTime.

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer

// 1. The code correctly converts movieLength into hours, minutes, and seconds for positive values.
// 2. It doesn’t handle zero or negative values properly—these cases need extra checks.
// 3. Minutes and seconds may appear without leading zeros.


27 changes: 26 additions & 1 deletion Sprint-1/3-mandatory-interpret/3-to-pounds.js

Choose a reason for hiding this comment

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

good analysis

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,29 @@ console.log(`£${pounds}.${pence}`);
// Try and describe the purpose / rationale behind each step

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
// 1. const penceString = "399p": initialises a string variable with the value "399p". The trailing "p" indicates the unit



//2. Removes the"p" at the end of the string.
To isolate the numeric part

//3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");

//Pad the numeric string with leading zeros to ensure it has at least 3 digits

//4.const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);
//Extract the pounds part by taking all but the last two digits

//5.Extract the pence part by taking the last two digits and pad with trailing zero if needed
const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");

// 6. Output the formatted price in pounds and pence
console.log(`£${pounds}.${pence}`);

// This program takes a string representing a price in pence
7 changes: 7 additions & 0 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
// i run alert("Hello World!");
// A box pop up in the browser window with the message:Hello World!
//It has an "OK" button that i must click to dismiss the alert

Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`.

What effect does calling the `prompt` function have?
What is the return value of `prompt`?

//const myName = prompt("What is your name?");
//a modal box appears with the message "What is your name?"
//there are OK AND Cancel buttons

Choose a reason for hiding this comment

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

good exploration - did you manage to find what the return value could be?

17 changes: 16 additions & 1 deletion Sprint-1/4-stretch-explore/objects.md

Choose a reason for hiding this comment

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

good answer

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,26 @@ Open the Chrome devtools Console, type in `console.log` and then hit enter

What output do you get?

Now enter just `console` in the Console, what output do you get back?
//ƒ log() { [native code] }

Now enter just `console` in the Console, what output do you get back?
//console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}
Try also entering `typeof console`

//object

Answer the following questions:

What does `console` store?

// it stores tools to show messages in the browser's console

What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?

//The . is the property accessor operator in JavaScript. It’s used to access properties or methods on an object. Here:

console is the object.

log or assert is a property of that object (specifically, a method/function).

So, console.log means: “Access the log method on the console object.”
7 changes: 7 additions & 0 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.

Good explanation, can you provide some new code that works correctly?

Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// Predict and explain first...
// =============> write your prediction here

// The code will throw an error because the variable `str` is being declared twice in the same scope.

// 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;
}
capitalise("hello,this is a test");

//

// =============> write your explanation here
// =============> write your new code here
//// The error occurs because the variable `str`is declared twice in the same scope,which is not allowed in JavaScript.
10 changes: 10 additions & 0 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// Why will an error occur when this program runs?
// =============> write your prediction here
//Decimal number is undefined
//we ll got syntax error as we are declaring a new variable

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

Expand All @@ -18,3 +20,11 @@ console.log(decimalNumber);

// Finally, correct the code to fix the problem
// =============> write your new code here
function convertToPercentage(decimalNumber) {

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

return percentage;
}

result = console.log(convertToPercentage(0.5));
14 changes: 13 additions & 1 deletion Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,28 @@

// =============> write your prediction of the error here

//we will get an error bcs the parameter of the function need to string type not number so it can be something like num

Choose a reason for hiding this comment

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

Could you explain what you mean by the parameter needing to be a string type?

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

// =============> write the error message here
//Output:

/index.js:1
function square(3) {
^

SyntaxError: Unexpected number
// =============> explain this error message here

// Finally, correct the code to fix the problem

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


//THe error message tells that we wrote a syntax that JavaScript does not understand.
function square(num) {
return num * num;
}
result = console.log(square(3));
10 changes: 8 additions & 2 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// Predict and explain first...

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

// What I predict is that the console.log which is outside the function will pass the parameters 10 and 32 to the function
// Then the console.log(a * b) which is inside the function will print out
// to the terminal the multiplication of a by b
function multiply(a, b) {
console.log(a * b);
const multiplicationResult = (a * b);
return multiplicationResult;



}

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