Skip to content

LONDON |ITP-MAY-2025| KHILOLARUSTAMOVA | Coursework/sprint1 #588

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 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
// The = operator updates the value of count by assigning it a new value so count is not =0 anymore it is = to 1

6 changes: 3 additions & 3 deletions Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ let middleName = "Katherine";
let lastName = "Johnson";

// Declare a variable called initials that stores the first character of each string.
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.

let initials = ``;
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution

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

//Get the first character of each name using [0]
let initials = firstName[0] + middleName[0] + lastName[0];
9 changes: 5 additions & 4 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
// (All spaces in the "" line should be ignored. They are purely for formatting.)

const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
const lastSlashIndex = filePath.lastIndexOf("/"); // 55
const base = filePath.slice(lastSlashIndex + 1); // file.txt
console.log(`The base part of ${filePath} is ${base}`);

// Create a variable to store the dir part of the filePath variable
// Create a variable to store the ext part of the variable

const dir = ;
const ext = ;
const dir = filePath.slice(0,lastSlashIndex);
const dotIndex=filePath.lastIndexOf(".");
const ext = base.slice(dotIndex+1);

// https://www.google.com/search?q=slice+mdn
32 changes: 32 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,38 @@ const maximum = 100;

const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;


Math.random()

This gives you a random decimal number between 0 (inclusive) and 1 (not including 1).

Example output: 0.3, 0.89, 0.01, etc.

(maximum - minimum + 1)

This calculates how many possible numbers there are between minimum and maximum, including both.

In this case: 100 - 1 + 1 = 100 possible numbers.

Math.random() * (maximum - minimum + 1)

Multiplies the random decimal by 100. This gives a number between 0 and just under 100.

Example: If Math.random() gives 0.66, then 0.66 * 100 = 66.

Math.floor(...)

Rounds the result down to the nearest whole number.

So 66.8 becomes 67.

+ minimum

This shifts the range from 0–99 to 1–100.

So if Math.floor(...) gave 67, then adding 1 gives 68.


// In this exercise, you will need to work out what num represents?
// 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
Expand Down
16 changes: 15 additions & 1 deletion Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
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?
Single-line comment
Use // at the beginning of the line:


// This is just an instruction for the first activity
// We don't want the computer to run these 2 lines
Multi-line comment
Use /* */ for multiple lines:

/*
This is just an instruction for the first activity.
We don't want the computer to run these 2 lines.
*/

5 changes: 5 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,8 @@

const age = 33;
age = age + 1;
// to be able to reassign the value we need to use let instead of const because the value of const can not be changed after it is set.
let age = 33;
age = age + 1;


6 changes: 6 additions & 0 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";

// this code has order problem. const and let has to have it`s value has to be declared before you use it.
// to fix it we will change the order of the code.

const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
7 changes: 7 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,10 @@ 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


This will give an error because cardNumber is a number, and .slice() is a method that only works on strings or arrays — not numbers.
for this to work we need to change the card number to a string

const cardNumber = "4533787178994213"; // use quotes to make it a string
const last4Digits = cardNumber.slice(-4);
13 changes: 12 additions & 1 deletion Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";

//Variable names in JavaScript cannot start with a number.
// so we have to change 12 to twelve and 24 to twentyFour

const twelveHourClockTime = "08:53"; // 12-hour time (8:53 AM)
const twentyFourHourClockTime = "20:53"; // 24-hour time (8:53 PM)

// we can also put it this way:

const clock12 = "08:53";
const clock24 = "20:53";
55 changes: 55 additions & 0 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,58 @@ 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) in total we have 5 function calls here:
Line 4: carPrice.replaceAll(",", "")

Line 4: Number(...)

Line 5: priceAfterOneYear.replaceAll("," "") — this line has an error (missing comma)

Line 5: Number(...)

Line 8: console.log(...)


//b) on line 5 there is a missing coma between arguments. (",""") should be (",","")

//c) The variable reassignment statements are:

Line 4: carPrice = Number(carPrice.replaceAll(",", ""));

Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));

Line 8: console.log(`The percentage change is ${percentageChange}`);

//d) The variable declarations are:

// Line 1: let carPrice = "10,000";

// Line 2: let priceAfterOneYear = "8,543";

// Line 6: const priceDifference = carPrice - priceAfterOneYear;

// Line 7: const percentageChange = (priceDifference / carPrice) * 100;

// e) The expression

carPrice.replaceAll(",", "") removes all commas from the string (e.g., turns "10,000" into "10000").

Number(...) converts the resulting string "10000" into a number type 10000.

Purpose: To convert a formatted string number with commas into an actual number so you can do arithmetic on it.












28 changes: 25 additions & 3 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,36 @@ 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?
1) const movieLength = 8784; // length of movie in seconds

2) const remainingSeconds = movieLength % 60;
3) const totalMinutes = (movieLength - remainingSeconds) / 60;

4) const remainingMinutes = totalMinutes % 60;
5) const totalHours = (totalMinutes - remainingMinutes) / 60;

6)const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;

// b) How many function calls are there?
1)console.log(result);

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

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Ope
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
This line is finding the number of seconds left over after dividing the total movie length by 60 seconds (1 minute).

// e) What do you think the variable result represents? Can you think of a better name for this variable?
movieLength is the total time of a movie in seconds.

60 is the number of seconds in a minute.

% is the modulus operator — it gives you the remainder after division.


// e) What do you think the variable result represents? Can you think of a better name for this variable?
It represents the movie length formatted as hours, minutes, and seconds.
✅ A better name would be:
formattedTime
durationString
movieTimeFormatted
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
yes it works for different numbers