Skip to content

Londonl May-2025lping wanglCoursework/sprint 1 #641

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 19 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
6 changes: 5 additions & 1 deletion Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ 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
// Describe what line 3 is doing, in particular what=
Line one shows the initial value is 0 as a variable Declaration,
Line 3 on the right-hand side count + 1 is evaluated first which means the current value 0 adds 1, giving 1
The left-hand side count= means: Assign the result of right-hand side 1 back into the variable
count. So after this runs the output should be 1.
2 changes: 1 addition & 1 deletion Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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 = ``;
let initials = firstName[0]+middleName[0]+lastName[0];

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

11 changes: 9 additions & 2 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ 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
// Get everthing before base
const dir = filePath.slice(0,lastSlashIndex);

//Get everything after the last dot in the base:
const lastDotIndex = base.lastIndexOf(".");
const ext = base.slice(lastSlashIndex+1);

console.log('The dir part of ${filePath} is ${dir}');
console.log('The ext part of ${filePath} is ${ext}');

const dir = ;
const ext = ;

// https://www.google.com/search?q=slice+mdn
10 changes: 9 additions & 1 deletion Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ const maximum = 100;
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;

// 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
// Try breaking down the expression and using documentation to explain what it mean
// 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
num reprents the number is randomly generated whole number betweeb 1 and 100,inclusive
Math.random() returns a random decimal between 0(inclusive) and 1(exclusive). while maximum-minimum +1=100, Math.random()*(maximum-matchMedia+1)
range is between 0 and 99.99999
Due to that Math.floor(...) rounds down the decimal to the nearest whole number.From this Stage, we have interger between o and 99.
After + minimum, the range is between 1 and 100.
This is classcial expressions for generating a random interger between two values- between 1 and 100, inclusive in this function.
This kind of expression is commonly used for things like: rolling dice,random quiz questions, game mechanics.
6 changes: 4 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
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?
// 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?

In JavaScript, we put // in front of sentence which is only for human to read.
3 changes: 2 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 33;
age = age + 1;
console.log(age);
3 changes: 2 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?

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

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

//slice() only works for string or Array,cardNumber is number so i predict that the computer will give TypeError. When i
//run this Code, my prediction is right. In order to fix it, first cast to string first:

const cardNumber=4533787178994213;
const last4Digits = cardNumber.toString.slice(-4);

//then conver to number
const last4Digits = Number(cardNumber.toString.slice(-4));
console log(last4Digits);

8 changes: 7 additions & 1 deletion Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";

// cost 12HourClockTime = "20.53" is wrong code because 20 is more than 12 and variable name can not start with digital in JavaScript.
// The right coe should be:

const TwelveHourClockTime = "8:53"
const TwentyFourHourClockTime = "20:53"
32 changes: 32 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,35 @@ 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?

//a: There are three function calls, which are: Number(...), replaceAll(...) and console.log(...)
// Function call lines: 1. carPrice = Number(carPrice.replaceAll(",", ""));
// 2. priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
// 3. console.log(`The percentage change is ${percentageChange}`);

//b: priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")) has an error,SyntaxError: Unexpected string
// missing a comma between the arguments of replaceAll.
// correct is: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",",""));

// c: two reassignment statements: 1.carPrice = Number(carPrice.replaceAll(",", ""));
// 2.priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));

// d: four variable declarations(using let or cost to declare new variables):
// 1. let carPrice = "10,000";
// 2. let priceAfterOneYear = "8,543";
// 3. const priceDifference = carPrice - priceAfterOneYear;
// 4.const percentageChange = (priceDifference / carPrice) * 100;

//e: 1.carPrice is a string like "10,000"
// 2.replaceAll(",", "") removes commas → becomes "10000"
// 3.Number(...) converts the string "10000" into the number 10000
// The purpose is to convert a currency string with commas (e.g., "10,000") into a usable number (10000) for math calculations.









21 changes: 21 additions & 0 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,24 @@ console.log(result);
// e) What do you think the variable result represents? Can you think of a better name for this variable?

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

// Answer a: there are 6 variable declarations which are const movieLength, const remainingSeconds, const totalMinutes, const remainingMinutes,
// cost totalHours and const result.

// Answer b: only one function call which is console.log(result).

// Answer c: it means the number of seconds left after removing all full minutes". so 8784%60=24, So there are 24 seconds remaining after
// converting to full minutes.It gives the number of seconds left after dividing total seconds into whole minute.

// Answer d:it calculates the number of full minutes in the total movie length. so 8784-24=8760/60=146 minutes

// Answer e: this builds a string representing the time in HH:MM:SS format, based on the movie length in seconds. The better name can be
// formattedTime or timeString.

// Answer e: It will work for most large integers or large hours but it does not work well for time below 60 seconds like 37 seconds is
// 0:0:37 which can be considered unformatted. What is more, it does not handle negative numbers and does not pad numbers with zero.





25 changes: 24 additions & 1 deletion Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,27 @@ 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",p means pence so 399p means 399 pence.

// 2.const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);Removes the trailing "p" from the string.
// .substring(0, length - 1) means: take all characters except the last one.Result: "399",which will get only the numeric part of the price.

// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");Pads the numeric part from the left with zeros
// until it's at least 3 characters long."399" stays as "399" (already 3 characters).if the number is 7, it becomes"007"
// Purpose: Ensures consistent formatting so the last two digits are always the pence and the rest are pounds.

// 4.const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);Extracts the pounds part from the padded number
// string.For "399", this gives: .substring(0, 1) → "3".Purpose: Get everything except the last two digits, which represent the pence.

// 5.const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");Extracts the last two characters
// (the pence part) and ensures it's exactly two digits by padding on the right if needed.For "399" → .substring(1) = "99", no padding needed
// For "3", it becomes "03". Purpose: Make sure the pence always shows as two digits.

// 6. console.log(£${pounds}.${pence});Constructs and logs a string in the proper pounds-and-pence format, like:text £3.99
// Purpose: Output the final, human-readable currency value.






24 changes: 23 additions & 1 deletion Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,26 @@ What effect does calling the `alert` function have?
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`?
What is the return value of `prompt`

>alert("Hello World!")
the pop up box:chrome://new-tab-page says Hello world! i press ok button, return undefined.the pop up box pauses JS execution until press ok
<.undefined
>myName = prompt("What is your name")
<.'ping'
Warning: Don’t paste code into the DevTools Console that you don’t understand or haven’t reviewed yourself. This could allow attackers to steal your identity or take control of your computer. Please type ‘allow pasting’ below and press Enter to allow pasting.
allow pasting
>let myName = prompt("What is your name?");
the pop up box:chrome://new-tab-page says, i ingnore blue box just press cancel,
<.console.log("Your name is:", myName);
VM255:2 Your name is: null
undefined
>let myName = prompt("What is your name?");
in pop up box: chrome://new-tab-page says, i put my name'ping' in blue box then press ok
<.console.log("Your name is:", myName);
VM259:2 Your name is: ping
undefined
The value returned from prompt() is stored in the variable myName. The pop up box pauses the JS execution until i press the button either'cancel' or put my name before press'OK'.



27 changes: 27 additions & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,30 @@ Answer the following questions:

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

what i get from Chrpme devtools Console:

>console.log
<.ƒ log() { [native code] }

>console
<.console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}

>typeof console
<.object'

'console store': console is an object provided by the browser (in this case, Chrome).It stores functions for outputting information to the Console, such as:log(): Print general information.error(): Print error messages.warn(): Show warnings.info(): Show info-level messages.
assert(): Log a message only if a condition is false....and more

What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
The . is the dot operator, used to access properties or methods of an object.
In console.log, you're accessing the log method on the console object.
So:
console = object
.log or .assert = method on that object

console is a built-in object
console.log is a method used to print messages to the Console
The . is used to access a method or property on an object


Loading