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
5 changes: 5 additions & 0 deletions Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@ let count = 0;

count = count + 1;

console.log(count);

// 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 value of the count variable by 1.
// The = operator assigns the result of (count + 1) back to count.
4 changes: 2 additions & 2 deletions Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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

8 changes: 5 additions & 3 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ 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:", dir);
console.log("ext:", ext);
// https://www.google.com/search?q=slice+mdns
9 changes: 9 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ const maximum = 100;

const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;

console.log(num);

// In this exercise, you will need to work out what num represents?
// num represents a random whole number between the minimum and maximum values.

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

// Step 1: Math.random() returns a decimal in [0, 1) (includes 0, excludes 1)
// Step 2: Multiply by 100 -> value is in [0, 100)
// Step 3: Math.floor(...) converts it to an integer in [0, 99]
// Step 4: Add 1 -> integer in [1, 100]
4 changes: 3 additions & 1 deletion 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?
We don't want the computer to run these 2 lines - how can we solve this problem?
*/
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);
7 changes: 4 additions & 3 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?
// what's the error ? THe error was "Cannot access" 'cityofBirth' before initialization.
// This happened becouse cityofBirth was used before it was declared.

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
const cityofBirth = "Bolton";
console.log(`I was born in ${cityofBirth}`);
9 changes: 8 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
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: It wont work because cardNumber is a number and slice() only works on strings.
Error: TypeError - cardnumber.slice is not a function.
Explanation: Numbers dont have the slice method.
*/
4 changes: 2 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const hour12HourClockTime = "20:53";
const hour24HourClockTime = "08:53";
12 changes: 11 additions & 1 deletion Sprint-1/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,21 @@ 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
// Line 4 has a function call
// Line 5 has a function call
// line 10 has a function call

// 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?
// I have spotted the error on line 5 there was a missing coma between the two arguments of replaceAll() specifically between "," and "".

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

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

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// replaceAll() removes commas and Number() converts the cleaned string into a number.
10 changes: 10 additions & 0 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?
// There is 6 Variable declarations
// Line 1 , Line 3 , Line 4 , Line 6 , Line 7 , Line 9

// b) How many function calls are there?
// There is 1 function call in 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
// The expression movieLength % 60 represents the remainder of the division of movieLength by 60.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// Line 4 removes the leftover seconds, then devides by 60.
// then divides the result by 60 to calculate the total full minutes.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// Result is a formatted time string in hours, minutes and seconds. A better name for this varible could be formattedTime.

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// I tested diffrent positive numbers and the code work correctly.
// However it well work properly for positive numbers.
// If movielength is negative or a decimal number , the output may not repeesent the time correctly.
10 changes: 9 additions & 1 deletion Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ console.log(`£${pounds}.${pence}`);

// You need to do a step-by-step breakdown of each line in this program
// Try and describe the purpose / rationale behind each step
// 1. Stores "399p" as a string
// 2. removes the "p" at the end
// 3. adds zeros at the start if needed to make it 3 digits.
// 4. Takes the last 2 digits as the pence part.
// 5. Uses padEnd to make sure the pence part always has 2 digits.
// padEnd(2, "0") might not be needed because the number was already padded before.

// To begin, we can start with
// I also tested it by changing 399p to 50p and the result was £0.50 thats shows diffrent numbers well have diffrent outputs

// To begin, we can start wit
// 1. const penceString = "399p": initialises a string variable with the value "399p"
7 changes: 4 additions & 3 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ Let's try an example.
In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
What effect does calling the `alert` function have? It displays a popup message box with a text saying Hello world! and pauses the website in until you click ok to unpause it.

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 effect does calling the `prompt` function have? The prompt function displays a popup box asking you to enter a text and pausing the page until you click ok or cancel.

What is the return value of `prompt`? Prompt returrns the text enterend by the user as a string if the user clicks OK, and returns null if the user clicks cancel.
7 changes: 5 additions & 2 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ Try also entering `typeof console`

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 does `console` store? Console is an object that stores debugging finctions.

What does the syntax `console.log` or `console.assert` mean? Console.log or console.assert means accesing a fuction inside the console object.

In particular, what does the `.` mean? The dot '.' is called dot notation and it used to access properties or methods of an object.
4 changes: 2 additions & 2 deletions Sprint-1/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This README will guide you through the different sections for this week.

## 1 Exercises

In this section, you'll have a short program and task. Some of the syntax may be unfamiliar - in this case, you'll need to look things up in documentation.
In this section, you'll have a short program and task. Some of the syntax may be unfamiliar - in this case, you'll need to look things up in documentation.

https://developer.mozilla.org/en-US/docs/Web/JavaScript

Expand All @@ -28,7 +28,7 @@ You must use documentation to make sense of anything unfamiliar - learning how t

You can also use `console.log` to check the value of different variables in the code.

https://developer.mozilla.org/en-US/docs/Web/JavaScript
https://developer.mozilla.org/en-US/docs/Web/JavaScript

## 4 Explore - Stretch 💪

Expand Down