Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
42df165
modified Key exercises files 1,2,and3
Sep 18, 2026
09045cf
Answer modified in 4-random.js
Sep 20, 2026
ffaed93
Answered 1-percentage-change.js
Sep 20, 2026
c504786
Debugged the problem of 1-percentage-change.js- a comma is placed be…
Sep 20, 2026
430be1d
Answered 2-time-format.js
Sep 20, 2026
0fc5678
Answered 3-to-pound.js
Sep 21, 2026
83a6fa1
minor format change in 2-time-format.js
Sep 21, 2026
0688923
Answered and reflected in chrome.md and object.md
Sep 21, 2026
5bd8824
Complete 2-mandatory -error from class
AlanGit-debug2604 Sep 20, 2026
8085ffc
Answer 1-count.js: describe line 3 and assignment operator
Sep 22, 2026
71e9cc8
Answer 4-random.js: describe what num represents, min and max
Sep 22, 2026
2d0acdc
Add specific error names to 2.js; clarify let vs const in 2.s
Sep 22, 2026
1e725d9
Delete the old code you commented out: 1.js lines 6 and 7, 2.js lines…
Sep 23, 2026
bfd04f3
Line adjusted. Answers in a) to d) now correspond to the right lines.
Sep 23, 2026
f0d0c8b
Answer f) with multiple test values including negative/decimal in 2-t…
Sep 23, 2026
b9108fd
Correct substring argument explanation in 3-to-pounds.js
Sep 23, 2026
df783e8
Apply Prettier formatting and fix line endings across all files
Sep 23, 2026
2ba7e15
put the trailingP back to line one in variable
Sep 23, 2026
5d16528
Wrote the TypeError on line 8
Sep 23, 2026
dc9d08d
Wrote the TypeError below my prediction line 8. Also ensured Prettier…
Sep 23, 2026
f2cbb98
Wrote the TypeError below my prediction line 8. Prediction matches.
Sep 23, 2026
9712617
Added SyntaxError on line 1
Sep 23, 2026
5cc5f90
Convert remaining files from CRLF to LF line endings
Sep 23, 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
2 changes: 2 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,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

//Line 3 is reassignment of variable "count". The new assignment adds 1 to current value of count, "=" is to assign value on right-hand side to variable on left.
22 changes: 12 additions & 10 deletions Sprint-2/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const firstName = "Creola";
const middleName = "Katherine";
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 = ``;

// https://www.google.com/search?q=get+first+character+of+string+mdn
const firstName = "Creola";
const middleName = "Katherine";
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 =
firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0);
console.log(initials);

// https://www.google.com/search?q=get+first+character+of+string+mdn
9 changes: 6 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,10 @@ 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 ext = filePath.slice(filePath.lastIndexOf("."));

// https://www.google.com/search?q=slice+mdn
console.log(dir);
console.log(ext);

// https://www.google.com/search?q=slice+mdn
12 changes: 12 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,15 @@ 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

// num represents a variable. The expression assign a value to this variable.
// Math.floor () and Math.random () are methods.
// The value inside Math.floor() is its argument. The return value of this argument is expression within the yellow parenthesis.
// The whole expression of variable "num" is that a float generated by method Math.random() is multiplied by return value of the range specified by value between declared variable by key word constant.
// The method Math.floor() then return greatest integer of the value of this product.
// And finally plus the value of minimum variable declared.

//`num` is a random integer between maximum and minimum inclusive.
// The smallest value of 'num' can be 1

console.log(num);
5 changes: 3 additions & 2 deletions Sprint-2/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
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?
//By adding two slashes at the begining of each line.
7 changes: 6 additions & 1 deletion Sprint-2/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// 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);

//This is a type error. For the expected result of 34, age should not be declared as a constant.
//let should be used instead of const because const is a constant variable and cannot be reassigned.
7 changes: 6 additions & 1 deletion Sprint-2/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 ?

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

//The error is that the variable should be declared as a constant before it is used in the console.log statement.

//This is a ReferenceError.
//In this code, the key word does not need to be constant, it can be let - if this is the case the variable city0fBirth can be reassigned in other lines - instead of constant (which cannot reassign variable).
10 changes: 7 additions & 3 deletions Sprint-2/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
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
// Expectation about the error : cardNumber is assigned a number value, a .slice function does not work on number
// The constant last4Digits should be assigned to a String (cardNumber) to perform .slice function.
// The code would result a TypeError. It matches my prediction.
const cardNumber = 4533787178994213;
const last4Digits = String(cardNumber).slice(-4);

console.log(last4Digits);
9 changes: 7 additions & 2 deletions Sprint-2/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
const 12HourClockTime = "8:53pm";
const 24hourClockTime = "20:53";
// It was a SyntaxError. An identifier cannot start with a numberical value

const TweleveHourClockTime = "8:53pm";
const TwentyFourhourClockTime = "20:53";

console.log(TweleveHourClockTime);
console.log(TwentyFourhourClockTime);
14 changes: 13 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 @@ -12,11 +12,23 @@ console.log(`The percentage change is ${percentageChange}`);
// Read the code and then answer the questions below

// a) How many function calls are there in this file? Write down all the lines where a function call is made
// There are five function calls in this code in lines 4, 5, and 10
// These function calls are Number, replaceAll, and console.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?
// The error originally came from the replaceAll call for priceAfterOneYear: the two arguments
// (",", "") were missing a comma between them, causing a SyntaxError.
// The fix was adding the missing comma so replaceAll(",", "") has two properly separated arguments.

// c) Identify all the lines that are variable reassignment statements
// Variable reassignment statements on lines 4 and 5.
// Variables carPrice and priceAfterOnYear are originally declared on lines 1 and 2, and reassigned on lines 4 and 5.

// d) Identify all the lines that are variable declarations
// They are lines 1,2,7 and 8.
// On lines 1 and 2, variables carPrice and priceAfterOneYear are declared by let.
// On lines 7 and 8, variables priceDifference and percentageChange are declared by const.

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// replaceAll(",", "") removes all comma characters from the string, since commas aren't valid in a numeric value.
// Number() then converts the resulting clean string into an actual number, so it can be used in arithmetic.
13 changes: 12 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 = -90.5; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -12,14 +12,25 @@ 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 six variable declarations in the program, namely :
// movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result

// b) How many function calls are there?
// One function call console.log() in code above.
// The others are declared variables.

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
// % is remainder operator. This operator returns the remainder after left operand is divided by 60.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// The expression means first exclude odd seconds, then convert the movie length in number of complete minutes.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// The variable result represents length of movie in H:M:S format. A better variable name can be movieLength_HMS

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// A value of movieLength 3661 will return a result of 1:1:1 where the place value for second does not conforms with leading zero time format.
//The code does not work for all values:
//It does not pad single digits with a leading zero;
//It does not validate to reject negative (e.g.-90 gives "0:-1:-30" ; -90.5 gives "0:-1:-30.5") or decimal input.
24 changes: 17 additions & 7 deletions Sprint-2/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
const penceString = "399p";
const penceString = "399p"; // initialises a string variable with the value "399p"

const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);
penceString.length - 1,
); // use .substring method to extract characters of numerical string, with zero indexing starting from first place of penceString, ending at one digit less than the length of penceString by method .length. Expecting value "399".

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
//declares paddedPenceNumberString variable. To target the length of pence number string in three characters. If not, "0" will be added at the beginning of the string. Expecting value "399".
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);
paddedPenceNumberString.length - 2,
); //declares variable for pound. .substring method starting from first character, ending by trimming last two characters by method .length. Expecting value "3"

const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
.padEnd(2, "0"); // declares variable for pence. The argument is paddedPenceNumberString.length - 2,
// which for "399" (length 3) evaluates to 1. So this returns .substring(1), giving the last two
// characters "99" — not a literal -2 argument.
// .padEnd method returns character length of two, if not, "0" will be added at the end of string, for examples "90". Here, expecting "99".

console.log(`£${pounds}.${pence}`);
console.log(`£${pounds}.${pence}`); // Prints the return value by Template Literal with '£X.yz" format in console pane.

// This program takes a string representing a price in pence
// The program then builds up a string representing the price in pounds
Expand All @@ -25,3 +29,9 @@ console.log(`£${pounds}.${pence}`);

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

// Five Variables declared:
// penceString, penceStringWithoutTrailingP, paddedPenceNumberString,pound, pence
// Three methods used:
//.substring(), .padStart(), .padEnd() .log()
// One property used: .length
3 changes: 3 additions & 0 deletions Sprint-2/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ Let's try an example.
In the Chrome console, invoke the function `alert` with one argument, the string `"Hello world!"`;

What effect does calling the `alert` function have?
(The function prompts an alert when pressing enter to run)

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?
(The'prompt'function opens a caveat dialog box, allows user to key in response. )
What is the return value of `prompt`?
(prompt(myName) will return value entered by user)
8 changes: 7 additions & 1 deletion Sprint-2/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ Open the Chrome devtools Console, type in `console.log` and then hit enter

What output do you get?

(ƒ 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?
(`console` stores an object. Note for question: where is this object source from?)
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
(`log` is a method to print object belongs to console. The `.` access that object stored in `console`)
(`assert`checks if a condition is true.)
Loading