Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f967651
Answer question in 1-count.js
habohlin Sep 15, 2026
f8342d2
Declare variable storing initials and logging it, in 2-initials.js
habohlin Sep 15, 2026
ac6e7f0
Declare and log dir in 3-paths.js
habohlin Sep 15, 2026
e161bfe
Declare and log ext in 3-paths.js
habohlin Sep 15, 2026
938fa67
Answering question in 4-random.js
habohlin Sep 15, 2026
8140310
Commented out the text in 0.js
habohlin Sep 15, 2026
e014f8c
Changed age variable to let in 1.js
habohlin Sep 15, 2026
128097d
Switched the lines to declare variable first in 2.js
habohlin Sep 15, 2026
4910cfa
Converted toString before using slice, in 3.js
habohlin Sep 15, 2026
b3b3e06
Removed numbers from start of var names in 4.js
habohlin Sep 15, 2026
1a2ca2e
Add comma to resolve syntax error and answer questions
habohlin Sep 15, 2026
81af5ee
Answer questions in 2-time-format.js
habohlin Sep 15, 2026
9a33391
Answer questions in 3-to-pounds.js
habohlin Sep 16, 2026
aedf788
Answer questions in chrome.md
habohlin Sep 16, 2026
b47a1f0
Answer questions in objects.md
habohlin Sep 16, 2026
18ec4c9
Changing answer to a) in 1-percentage-change.js
habohlin Sep 16, 2026
7002d6b
Changing the answer to b) in 2-time-format.js
habohlin Sep 16, 2026
8b85d0f
Explained the error message in 1.js
habohlin Sep 16, 2026
c81c96d
Explained the error message in 2.js
habohlin Sep 16, 2026
50f9d8c
Explained the error message in 4.js
habohlin Sep 16, 2026
49aa90d
Formatted all files with prettier
habohlin Sep 16, 2026
bf182f0
Fixed parth typo on line 21 in 3-paths.js
habohlin Sep 16, 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
4 changes: 4 additions & 0 deletions Sprint-2/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ 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: The = is an assignment operator (as opposed to == and === which are comparison operators).
// In line 3, a new value is assigned to the variable count. This is allowed because the variable was
// declared using let. count is reassigned to the old value of count plus 1.
4 changes: 3 additions & 1 deletion Sprint-2/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const 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.

const initials = ``;
const initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`;

console.log(initials);

// https://www.google.com/search?q=get+first+character+of+string+mdn
10 changes: 7 additions & 3 deletions Sprint-2/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ 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);
console.log(`The dir part of ${filePath} is ${dir}`);

// https://www.google.com/search?q=slice+mdn
const lastPeriodIndex = filePath.lastIndexOf(".");
const ext = filePath.slice(lastPeriodIndex);
console.log(`The ext part of ${filePath} is ${ext}`);

// https://www.google.com/search?q=slice+mdn
17 changes: 17 additions & 0 deletions Sprint-2/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,20 @@ 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

console.log(num);

// Answer: num is a random number between 1 and 100, including 1 and 100. So if I change the values of minimum
// and maximum it will be a random value between them, including them.

// Math.random generates a random value between 0 and 1, including 0 but not 1.

// (maximum - minimum + 1) gives the amounts of values we want to be able to generate.
// If minimum was 60 and maximum was 70, inclusive, that would make 11 possible values

// Math.random * (maximum - minimum + 1) would generate any value between 0 and 11, including 0 but not 11

// Math.floor rounds the value down, leaving us with any value between 0 and 10 inclusive

// + minimum at the end, 60 in our thought experiment, makes the values range between 60 and 70 inclusive
// which is what we wanted.
6 changes: 4 additions & 2 deletions Sprint-2/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?

// Answer: I turned the lines into comments, now they won't run
6 changes: 5 additions & 1 deletion Sprint-2/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 33;
age = age + 1;

// Answer: I got the error message TypeError: Assignment to constant variable.
// That is because age was declared using const, which makes it non-reassignable.
// I changed the const to let, so the variable age becomes reassignable
6 changes: 5 additions & 1 deletion Sprint-2/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}`);
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);

// Answer: I got the error message ReferenceError: Cannot access 'cityOfBirth' before initialization
// This is because the program tries to access cityOfBirth before it has been initialized.
// I switched the lines around, so cityOfBirth gets declared before it is referenced.
16 changes: 15 additions & 1 deletion Sprint-2/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const last4Digits = cardNumber.toString().slice(-4);
console.log(last4Digits);

// 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

// Prediction: I believe slice counts forward from the start when you use positive values, and
// backwards from the end when you use negative. So if you only put in one negative number, it's counts
// backward from the end to the last 4, but can't "turn around" to count up to the end again..?

// After running the code: The actual error was a TypeError, saying that cardNumber.slice is not a function.
// That means you can't put anything in parenthesis after cardNumber.slice. However, when I used slice before
// slice definitely takes parameters. This made me think about the fact that cardNumber is actually a
// number, and slice is probably only for strings or arrays. You can't really count positions in a number.

// I solved it by chaining a toString before slicing. My initial theory was completely wrong, putting a
// negative number in slice is completely fine. Now last4Digits is a string, not a number. But it seems
// easier to work with as a string, if specific digits need to be accessed, so I will keep it as a string.
8 changes: 6 additions & 2 deletions Sprint-2/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
const 12HourClockTime = "8:53pm";
const 24hourClockTime = "20:53";
const twelveHourClockTime = "8:53pm";
const twentyfourHourClockTime = "20:53";

// Answer: I got the error message SyntaxError: Invalid or unexpected token
// There were arrows pointing at "12" in 12HourClockTime. That is because
// variable names cannot start with numbers in javascript. I changed them to start with letters.
22 changes: 21 additions & 1 deletion Sprint-2/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let carPrice = "10,000";
let priceAfterOneYear = "8,543";

carPrice = Number(carPrice.replaceAll(",", ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));

const priceDifference = carPrice - priceAfterOneYear;
const percentageChange = (priceDifference / carPrice) * 100;
Expand All @@ -13,10 +13,30 @@ console.log(`The percentage change is ${percentageChange}`);

// a) How many function calls are there in this file? Write down all the lines where a function call is made

// 5 function calls are made.
// Line 4 calls function replaceAll and Number
// Line 5 calls functions replaceAll and Number
// Line 10 calls log

// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem?

// There is a syntax error. The error says a closing parenthesis is missing, which I think is triggered
// because a comma in the argument list is missing. I added the comma and the error is resolved.

// c) Identify all the lines that are variable reassignment statements

// Line 4 reassigning carPrice
// Line 5 reassigning priceAfterOneYear

// d) Identify all the lines that are variable declarations

// Line 1 declares carPrice with let
// Line 2 declares priceAfterOneYear with let
// Line 7 declares priceDifference with const
// Line 8 declares percentageChange with const

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

// The original carPrice is a string. In order to do math and get a percentage the string needs to be converted
// into a number first. And before that the string's comma needs to be removed (it's replaced with nothing
// using replaceAll)
22 changes: 21 additions & 1 deletion Sprint-2/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const movieLength = 8784; // length of movie in seconds
const movieLength = 145678; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -13,13 +13,33 @@ console.log(result);

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

// 6

// b) How many function calls are there?

// 1, console.log(result) on line 10

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

// % is the remainder arithmetic operator. The expression gives the remainder after the number of seconds
// the movie is long is divided by 60. After you have the full amount of minutes this is the amount of
// remaining seconds that don't add up to a full minute.

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

// removing remainingSeconds from movieLength leaves a number of seconds, slightly shorter than the movie length,
// that are an exact amount of minutes. It is divisible by 60. Dividing that number by 60 gives the exact
// number of minutes.

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

// It represents the movie length as a string expressed in hours, minutes and seconds. A different name could
// be moiveLengthDestructured, movieLengthMessage, movieLengthInHMS, movieLengthFormatted, movieLengthTimeFormat

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

// It technically works for all movie lengths, but the format gets weird. when a value is a single digit, you
// would expect 05 or 00, but it just says 5 or 0 which isn't a standard way to show time. Also, when the
// hours go above 24 you would expect it to start counting days, but the hours just add up instead as
// you try higher values.
43 changes: 41 additions & 2 deletions Sprint-2/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ const penceString = "399p";

const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
penceString.length - 1,
);

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

const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
paddedPenceNumberString.length - 2,
);

const pence = paddedPenceNumberString
Expand All @@ -25,3 +26,41 @@ console.log(`£${pounds}.${pence}`);

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

// Answers

// 2. const penceStringWithoutTrailingP = penceString.substring(
// 0,
// penceString.length - 1
// );
// This declares and initialises a new variable penceStringWithoutTrailingP that is a substring of
// penceString, starting at position 0 and up to but not including the last position. So the new variable
// gets the value "399", the p is left behind.

// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
// We now want our value to be at least 3 digits long, but in case it is shorter, we want to fill up with zeros at
// the start so it becomes 3 digits long. padStart does that, the 3 specifies minimum amount of digits and the "0"
// specifies what to fill with. The result gets saved in new variable paddedPenceNumberString.

// 4. const pounds = paddedPenceNumberString.substring(
// 0,
// paddedPenceNumberString.length - 2
// );
// Now we save the pounds amount into new variable pounds. We get the amount (which could be any amount of digits long)
// by creating a substring from paddedPenceNumberString starting at position 0 and ending before the next to
// last digit. The last two digits are the pence amount and they aren't included in pounds.

// 5. const pence = paddedPenceNumberString
// .substring(paddedPenceNumberString.length - 2)
// .padEnd(2, "0");
// Similarly to the previous operation, here we save the pence amount into new variable pence. We get it by
// using substring on paddedPenceNumberString again, this time starting two digits from the end, saving the
// final two digits into pence. Then, if the digits are fewer than 2, we chain a padEnd to add "0" until pence
// is 2 digits long.
// After trying different values, it seems like it is unnecessary to have the padEnd, since the pence will
// always already be 2 digits long. Even if penceString started with just 1 digit, "0"s will have been padded
// earlier at the beginning of the string, so pence can always be 2 digits and the padEnd will never take effect.

// 6. console.log(`£${pounds}.${pence}`);
// Using a template literal, here we log the £ sign followed by the the pounds amount, a period and the pence
// amount, which is formatted to understand easier than the original penceString was.
7 changes: 7 additions & 0 deletions Sprint-2/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ In the Chrome console, invoke the function `alert` with one argument, the string

What effect does calling the `alert` function have?

Answer: An alert popped up

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?

Answer: A poppup prompts me to write my name.

What is the return value of `prompt`?

Answer: The value I entered in the text box.
12 changes: 12 additions & 0 deletions Sprint-2/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ Open the Chrome devtools Console, type in `console.log` and then hit enter

What output do you get?

Answer: f log() { [native code] }

Now enter just `console` in the Console, what output do you get back?

Answer: console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}

Try also entering `typeof console`

Answer: it's an 'object' !!!

Answer the following questions:

What does `console` store?

Answer: A console object with loads of console functions (methods)?

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

Answer: I think the period means it's a method call, for console object methods. and log and assert are the
methods.
Loading