Skip to content
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
3 changes: 2 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,5 @@ 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
// Line 3 increments the variable by 1

5 changes: 4 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,10 @@ 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

4 changes: 2 additions & 2 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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 =base.slice(base.lastIndexOf(".") + 1)

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

//num is a random number [1,100]
//Math.floor rounds the decimal number to nearest lower number
// Math.random() generates a random decimal number between 0 and 1
Comment on lines +12 to +15
Copy link
Contributor

Choose a reason for hiding this comment

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

Phrases like "a number between X and Y" are not precise enough in a program specification, because they do not clearly state whether the endpoints X and Y are included.

We can also use the concise and precise interval notation to describe a range of values.

  • [, ] => inclusion
  • (, ) => exclusion

For example, [1, 10) means, all numbers between 1 and 10, including 1 but excluding 10.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you. I have changed this now.

Copy link
Contributor

@cjyuan cjyuan Mar 3, 2026

Choose a reason for hiding this comment

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

This description is still a bit ambiguous. It doesn't quite tell me whether 0 and 1 are included in the range or not.

// Math.random() generates a random decimal number between 0 and 1

// when max – min need to add +1 or not all the numbers will be
// included for instance max=5 min=1 5-1=4 but there are
// 5 numbers, 1, 2, 3, 4,5 so need to +1
//• + minimum → shift the range up to start at the minimum value
5 changes: 3 additions & 2 deletions Sprint-1/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?
//putting two forward slashes at the start of the line makes it a comment, which means the computer will ignore it when running the program
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;
//const age = 33; needs to be let or the value cannot be reassigned
let age = 33;
age = age + 1;
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}`);
//console.log(`I was born in ${cityOfBirth}`);
//const cityOfBirth = "Bolton";
// these are in the wrong order. Cannot access the value of cityOfBirth before it has been declared. Need to declare the variable first and then log it to the console.

const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
13 changes: 13 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,16 @@ 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


//cardNumber is a number and slice does not work with numbers only strings
// to fix this we can convert the number to a string and then use slice
// to get the last 4 characters of the string, which will be the last 4 digits of the original number
// const last4DigitsString = cardNumber.toString().slice(-4);
// or make it into a function that takes a number as an argument and returns the last 4 digits as a string

function last4Digits(cardNumber) {
return `${cardNumber}`.slice(-4);
}

console.log(last4Digits(cardNumber));
4 changes: 3 additions & 1 deletion Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";
// variable names cannot begin with a number
// can change to clockTime12Hour and clockTime24Hour or something similar to make it valid
14 changes: 14 additions & 0 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,25 @@ 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 4 function calls - Replace All is called twice and Number is called twice
// if console.log is considered a function call then there are 5 function calls in total

// 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 comma missing in line 5 it should be
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
// Replace All requires two arguments which should be separated by a comma, without the comma
// it cannot tell where the first argument ends and the second argument begins

// c) Identify all the lines that are variable reassignment statements
// there are 2 variable reassignment statements
// carPrice is reassigned on line 4 - the original value was declared in the let statement on line 1
// priceAfterOneYear is reassigned on line 5 - the original value was declared in the let statement on line 2

// d) Identify all the lines that are variable declarations
// variable declarations are where the variable is declared for the first time
// This happens in lines 1, 2 with let statements and in lines 7, 8 with const statements

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// it replaces the commas in the numbers such as 20,000 so calculations can be done
// with commas the numbers are recognised as a string but with spaces they can be recognised as numbers
// calculations cannot be performed on strings so they need to be converted to numbers
15 changes: 14 additions & 1 deletion Sprint-1/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 = 15560; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -12,14 +12,27 @@ 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 6 variable declarations - remainingSeconds, totalMinutes, remainingMinutes,
// totalHours, result and movieLength

// b) How many function calls are there?
// there is 1 function call - console.log is called on the last line to print the result to the console

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
// It is counting the remaining seconds after all the full minutes have been taken out of the movie length.
// For example if the movie length is 125 seconds, then 125 % 60 would give us 5 seconds remaining after taking out the full minutes (2 minutes in this case).

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// The expression (movieLength - remainingSeconds) / 60 calculates the total number of minutes in the movie length.
// It subtracts the remaining seconds from the total seconds and then divides by 60 to get the total minutes.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// result gives the length of the movie in hours, minutes and seonds
// a better name may be movieLengthFormatted or something similar

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// Yes, this code will work for all values of movieLength
//%60 gives the remainder and the remainder is always taken away before dividing for minutes and hours
// so it will always give the correct number of hours, minutes and seconds regardless of the length of
// the movie in seconds.
21 changes: 21 additions & 0 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const pounds = paddedPenceNumberString.substring(
paddedPenceNumberString.length - 2
);


const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
Expand All @@ -25,3 +26,23 @@ 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):
// removes the last character "p" from the string to get just the number part of the price in pence

//3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"):
// checks if the number is 3 digits and if it is less than 3 digits adds leading zeros to make it 3 digits long
// if it is less than 3 digits long it adds leading zeros ie if 5p it would become 005

//4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2):
// Ignores the last 2 numbers in the string (these are pence) and defines the remaining numbers as pounds.
// So if the number was 399 that would be £3. If th number was 2050 that would be £20
// if it was 5p it would be 0

//5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"):
// takes the last 2 numbers of the string which represent the pence and if it is less than 2 digits adds trailing zeros to make it 2 digits long
// due to step 3 the string should always have at least 3 numbers but this is a safety precaution

//6. console.log(`£${pounds}.${pence}`): prints the final result in the format of £pounds.pence to the console
// prints the result £pounds.pence so in this case £3.99 it prints the £ sign then the value of pounds
// designated by the $ sign and the value of pence designated by the $sign
13 changes: 13 additions & 0 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@ In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
a pop up box appears saying thecharitych.com says this is an alert

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?
a pop up box appears saying thecharitych.com says What is your name

What is the return value of `prompt`?

Using:
const myName = prompt("What is your name?");
console.log(myName);

If I click ok without entering my name the prompt goes off the screen and console.log returns undefined

If I click cancel without entering my name the promptgoes off the screen and console.log null undefined

If I put my name Hayriye in and click ok then it goes off the screen and console.log returns Hayriye
Comment on lines +27 to +31
Copy link
Contributor

Choose a reason for hiding this comment

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

These are all good test cases and observation.
In each case, what value does prompt() return?

Notes:

  • console.log() outputs the value you see on console; it does not return those values.
  • For more definite info about prompt(), "MDN Web Docs" is a good resource.

19 changes: 19 additions & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,31 @@ 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] }

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 functions and allows you to display and inspect information in the browser console.

What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
console.log prints the value of whatever you ask it to print ie console.log(portfolio) would print the value of portfolio whereas console.log("portfolio") would print the actual word portfolio.

console.assert tests for a condition but only returns a message if the condition is false. For instance it may be used to check the age of a person to restrict access to a site for adults only.

the full stop is used to separate an object from its method.
In console.log and console.assert console is the object and log and assert are methods.
The full stop is called the 'dot operator' or 'member access operator'
The dot operator accesses a property or method of an object
For example console.log means access the log method from the console object
and console.assert means access the assert method from the console object