Skip to content
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
079ec48
Describe what line 3 is doing
MahirShah300 Sep 19, 2026
f5838b7
Made string with first initial of all 3 strings
MahirShah300 Sep 19, 2026
23d7203
Change initial to const and define at initialisation
MahirShah300 Sep 19, 2026
fc7d149
Complete dir and ext strings
MahirShah300 Sep 19, 2026
7ca09e8
Explain num and expression
MahirShah300 Sep 19, 2026
eee3689
Made sentences comments
MahirShah300 Sep 19, 2026
ea56b8e
Explain error and how to fix
MahirShah300 Sep 19, 2026
a56a087
Explain error and how to fix
MahirShah300 Sep 19, 2026
a20ac92
Explain error. Fixed by using modulo 10000 instead of slice
MahirShah300 Sep 19, 2026
ced7487
Explain error, variables starting with number. Explain how to fix
MahirShah300 Sep 19, 2026
6d1fdd2
Answer all questions
MahirShah300 Sep 19, 2026
1de4780
Answered questions
MahirShah300 Sep 19, 2026
c9b584a
Answered questions in chrome.md
MahirShah300 Sep 19, 2026
8e63d7e
Answered questions in objects.md
MahirShah300 Sep 19, 2026
715631a
Format with prettier
MahirShah300 Sep 19, 2026
dfceb22
Fix initials variable to evaluate charAt expressions by removing quot…
MahirShah300 Sep 21, 2026
710a9bd
Format with prettier
MahirShah300 Sep 21, 2026
3ea71eb
Fix initials variable to evaluate charAt expressions by removing quot…
MahirShah300 Sep 21, 2026
83b9be5
Fix dir variable by not taking root part
MahirShah300 Sep 21, 2026
9cc571d
Correct explanation
MahirShah300 Sep 21, 2026
42695b2
Fix assignment of age by making changing const to let
MahirShah300 Sep 21, 2026
c837210
Fix by moving declaration above console.log line
MahirShah300 Sep 21, 2026
744d864
Fix variable name by moving number to end of name. Fix formatting
MahirShah300 Sep 21, 2026
3efcedd
Correct answers to questions
MahirShah300 Sep 21, 2026
d839a56
Correct answers to question
MahirShah300 Sep 21, 2026
59faf6f
Correct answers to question. Fix formatting
MahirShah300 Sep 21, 2026
e2994d8
Fix dir variable by taking root, leaving out last / by using lastSlas…
MahirShah300 Sep 21, 2026
4166f54
Fix formatting
MahirShah300 Sep 21, 2026
28690ca
Fix formatting
MahirShah300 Sep 21, 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

//Updating the value of count by adding 1 to it's current value. = is assigning
2 changes: 1 addition & 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,6 @@ 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)`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add console.log(initials); under this line and run the file. What does it print? Have a look at what the backticks are doing to the three expressions inside them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. It prints CKJ now.


// https://www.google.com/search?q=get+first+character+of+string+mdn
7 changes: 4 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,8 @@ 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, filePath.indexOf(base));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log dir and compare it to the diagram at the top of the file. Is the / before file.txt part of dir, or is it the separator between dir and base?

Also try filePath = "/Users/mitch/my.folder/photo.jpeg" and see what indexOf(base) does there.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It prints Users/mitch/cyf/Module-JS1/week-1/interpret/ now. Compare both ends with the diagram. The first / is the root. The root is part of dir. The last / is the separator. It is not part of dir. You already have its position on line 13.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now. The ext change to lastIndexOf is a good extra, too.

const ext = filePath.slice(-(filePath.length - filePath.indexOf(".")));
console.log(ext);

// https://www.google.com/search?q=slice+mdn
// https://www.google.com/search?q=slice+mdn
9 changes: 9 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,12 @@ 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 is a random, rounded down number between 100 and 1.
//math.floor rounds down.
//math.random gives a random number between 0 and 1. It can be equal to 0, but not equal to 1,
//(maximum - minimum + 1) gives in this case 100
//So then Math.random() * (maximum - minimum + 1) gives a number between 0 and 99
//Math.random() * (maximum - minimum + 1) gives a number between 1 and 100

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line says the same expression as line 15 gives 1 to 100. Both cannot be true. Which part of the full expression on line 4 shifts the range from 0..99 up to 1..100?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the one.

//and thus Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; gives a whole rounded
//down number
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?
//Make it code
5 changes: 5 additions & 0 deletions Sprint-2/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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run node 1.js as it stands. It still throws. Your fix is written in a comment on line 9, but it needs to be in the code so the file runs. Once it is, delete line 9; git keeps the history for you.

Same in 2.js.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both run now. Good.


//TypeError: Assignment to constant variable.
//Age is constant so can't be reassigned
//To fix, change const to let, so line 3 becomes:
//let age = 33;
4 changes: 4 additions & 0 deletions Sprint-2/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@

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

//ReferenceError: Cannot access 'cityOfBirth' before initialization
//Trying to use cityOfBirth before it's defined
//To fix, put line 5 before line 4, so it is initialised before use
6 changes: 5 additions & 1 deletion 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);
const last4Digits = cardNumber % 10000;
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

//TypeError: cardNumber.slice is not a function
//cardNumber is an integer, and slice is a string method, so slice doesn't work on cardNumber
4 changes: 4 additions & 0 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";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file still has the original names, so nothing in it runs. Rename both variables so the file runs, and keep your explanation underneath.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runs now. Good.

const 24hourClockTime = "20:53";

//SyntaxError: Invalid or unexpected token
//In javascript, variable names cannot start with a number.
//To fix, either put number at the end or start with _
6 changes: 6 additions & 0 deletions Sprint-2/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ 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
//5 function calls. 2 in line 7, 2 in line 8, 1 in line 10

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your count of 5 is right. Look again at the lines you listed. What is on line 7 and line 8, and is anything being called there? Then look at lines 4 and 5.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now.


// 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?
//Error is from line 5, no comma separating arguments for replace all. fix by adding comma after ","

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

// d) Identify all the lines that are variable declarations
//1, 2, 7, 8

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
//takes the string 10,000 and replaces all the commas with empty string, effectively removing the comma
//makes the string into number format so it can be converted to a number
12 changes: 11 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 = 5; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -12,14 +12,24 @@ 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?
//5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Count the lines above that use const or let. I make it 6. Which one have you missed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's it.


// b) How many function calls are there?
//1

// 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 modulo operator, which gives the remainder after operand.
//so in this case, the remainder of movieLength/60,
// the number of seconds not in a whole minute

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
//Take the total number of seconds in the move, minus the remainder of movieLength/60 to give
//a number that divides exactly by 60, then divide that number by 60. it converts the
// time into minutes

// e) What do you think the variable result represents? Can you think of a better name for this variable?
//The number of whole minutes in the movie. numFullMinutes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result is built on line 9 from three separate variables. Run the file and look at what it prints. Is that a number of minutes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good name.


// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
//Yes the math is fine and works with all numbers.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try movieLength = 8784, then -90, then "abc". What does each one print? Are all three sensible as a time?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good answer.

30 changes: 28 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,13 @@ 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 +25,29 @@ console.log(`£${pounds}.${pence}`);

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

// 2. const penceStringWithoutTrailingP = penceString.substring(
// 0,
// penceString.length - 1
//);
// finds a substring starting at 0 index to 1 before the last index, and assigns the
// substring to penceStringWithoutTrailingP. This removes the p and leaves us with just
// the number

// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
// Makes it so that the string is always at least 3 characters, by adding leading 0 until
// it is 3 characters long.

// 4. const pounds = paddedPenceNumberString.substring(
// 0,
// paddedPenceNumberString.length - 2,
//);
// Finds the substring of number paddedPenceNumberString, with the last 2 digits cut off
// basically finds the number of pounds by cutting off the pence

// 5. const pence = paddedPenceNumberString
// .substring(paddedPenceNumberString.length - 2)
// .padEnd(2, "0");
// Takes the substring starting at the total length-2, to the end. Essentially taking the
// last 2 digits
// Then adds 0 to the beginning so it is at least 2 characters long

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things here. padEnd does not add to the beginning, check the MDN page for which end it pads.

And there is no step 6 yet for line 18; what does that last line do?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both fixed.

4 changes: 4 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,12 @@ 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?
Message window at the top, that takes over the window with the message of the argument

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`?

prompt creates a window at the top with a text input box, with the message passed as the argument
the return value is whatever was written in the box
86 changes: 86 additions & 0 deletions Sprint-2/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,98 @@ In this activity, we'll explore some additional concepts that you'll encounter i
Open the Chrome devtools Console, type in `console.log` and then hit enter

What output do you get?
ƒ log() { [native code] }, which is telling me what it is, a function

Now enter just `console` in the Console, what output do you get back?
assert
:
ƒ assert()
clear
:
ƒ clear()
context
:
ƒ context()
count
:
ƒ count()
countReset
:
ƒ countReset()
createTask
:
ƒ createTask()
debug
:
ƒ debug()
dir
:
ƒ dir()
dirxml
:
ƒ dirxml()
error
:
ƒ error()
group
:
ƒ group()
groupCollapsed
:
ƒ groupCollapsed()
groupEnd
:
ƒ groupEnd()
info
:
ƒ info()
log
:
ƒ log()
memory
:
MemoryInfo {totalJSHeapSize: 13400000, usedJSHeapSize: 11200000, jsHeapSizeLimit: 3760000000}
profile
:
ƒ profile()
profileEnd
:
ƒ profileEnd()
table
:
ƒ table()
time
:
ƒ time()
timeEnd
:
ƒ timeEnd()
timeLog
:
ƒ timeLog()
timeStamp
:
ƒ timeStamp()
trace
:
ƒ trace()
warn
:
ƒ warn()
Symbol(Symbol.toStringTag)
:
"console"
[[Prototype]]
:
Object
which is a list of methods in console

Try also entering `typeof console`

Answer the following questions:

What does `console` store?
methods to interact with the console
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
it means, from the object console, access the function log or assert.
the fullstop is the connector to access the methods
Loading