Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cbac6c9
initial message
pathywang Jun 28, 2025
ec6019a
code done
pathywang Jun 28, 2025
09f6da9
modified: Sprint-1/1-key-exercises/4-random.js
pathywang Jun 28, 2025
78c873b
new file: package-lock.json
pathywang Jun 28, 2025
887fcdd
explainaton
pathywang Jun 28, 2025
3cd21a7
minor change
pathywang Jun 28, 2025
024cbc0
syntax change
pathywang Jun 28, 2025
b2e0a5d
minor
pathywang Jun 28, 2025
fbf096a
answer question
pathywang Jun 28, 2025
700ffe3
modify code
pathywang Jun 28, 2025
589052b
error corrected
pathywang Jun 28, 2025
0d5917b
correct error
pathywang Jun 30, 2025
e06ea00
error correct
pathywang Jun 30, 2025
ff6aac5
question answered
pathywang Jun 30, 2025
f48e433
quesiton answered
pathywang Jun 30, 2025
eb00ebe
type error
pathywang Jun 30, 2025
9082058
explaination given
pathywang Jul 1, 2025
cd05719
JS code trying
pathywang Jul 1, 2025
fa07668
explaination
pathywang Jul 1, 2025
2d7234f
correct error
pathywang Jul 19, 2025
62528e6
correct error
pathywang Jul 19, 2025
1270352
error correct
pathywang Jul 19, 2025
de9068f
add console.log
pathywang Jul 21, 2025
42da013
amend
pathywang Jul 21, 2025
b0a3afc
amend
pathywang Jul 21, 2025
d7dbde9
add description
pathywang Jul 21, 2025
718a5a4
amend
pathywang Jul 21, 2025
ba7388c
practicing
pathywang Jan 31, 2026
9b20e8f
practicing
pathywang Feb 2, 2026
7106030
practicing
pathywang Feb 3, 2026
0d13cdf
complete coursework
pathywang Feb 3, 2026
ce86675
Merge branch 'CodeYourFuture:main' into coursework/sprint-1
pathywang Feb 3, 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
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 @@ -2,5 +2,9 @@ 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 3 on the right-hand side count + 1 is evaluated first which means the current value 0 adds 1, giving 1
//= means: Assign the result of right-hand side 1 back into the variable, named count. So after line 3, output should be 1
4 changes: 3 additions & 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,9 @@ 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];

console.log(initials)

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

11 changes: 8 additions & 3 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@

const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
const base = filePath.slice(lastSlashIndex + 1)
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
//Get everything after the last dot in the base:
const dir = filePath.slice(0,lastSlashIndex+1);
const ext = base.slice(-3);

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
12 changes: 10 additions & 2 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ 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

// Try logging the value of num and running the program several times to build an idea of what the program is doingnum reprents the number is randomly generated whole number betweeb 1 and 100,inclusive range is between 0 and 99.99999

//Math.random() returns a random decimal between 0(inclusive) and 1(exclusive). while maximum-minimum +1=100, Math.random()*(maximum-minimum+1)

//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 integer 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);
6 changes: 5 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// 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}`);
//my answer:
// we should put variable declaration first then print out as JS languages rules, can not write the other way around

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

18 changes: 15 additions & 3 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);

// The last4Digits variable should store the last 4 digits of cardNumber
// However, the code isn't working
// Before running the code, make and explain a prediction about why the code won't work
// 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

//my answer:
//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;

//then convert to string
const last4Digits = cardNumber.toString().slice(-4);
console.log(last4Digits);

// or i can put quotes on cardNumber which will be string
const cardNumber1 ="4533787178994213"
const last4Digits1 = cardNumber1.slice(-4);
console.log(last4Digits1)
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 = "08:53 pm"
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": declare string variable with the value "399p" assigned,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 ignore 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 Chrome 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
Loading