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
1 change: 1 addition & 0 deletions Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ 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
//It assigns the variable"count" a new value of "count+1" which is "1"
9 changes: 8 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,14 @@ 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.charAt(0)+middleName.charAt(0)+lastName.charAt(0);

//or

let initials=firstName[0]+middleName[0]+lastName[0]



// https://www.google.com/search?q=get+first+character+of+string+mdn

// I really can't understand any of the documentation from developer.mozilla
6 changes: 4 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,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(1,lastSlashIndex);

const extPart=base.lastIndexOf(".")
const ext = base.slice(extPart);

// https://www.google.com/search?q=slice+mdn
11 changes: 11 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ const maximum = 100;
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;

// In this exercise, you will need to work out what num represents?
//num represents a variable with the a random number as its value

// Try breaking down the expression and using documentation to explain what it means
//Math.random() returns a pseudo random number that's >=0 and <1
//Math.floor() rounds down to the nearest integer

// It will help to think about the order in which expressions are evaluated
//this first (maximum-minimum+1) then this Math.random()* then this Math.floor() then this +minimum

// Try logging the value of num and running the program several times to build an idea of what the program is doing
//it returns a pseudo random number that's >=0 and <1


console.log(num);
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?
// By commenting out the lines
2 changes: 2 additions & 0 deletions Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

const age = 33;
age = age + 1;
//the "age" variable has been declared with a const and already assigned a value and it can not
// be reassigned another value because of the "const"
1 change: 1 addition & 0 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
//a variable needs to be declared before being initialized
12 changes: 10 additions & 2 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
// 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


//prediction: it won't work because the value of cardNumber is a number and slice() is a string method
const cardNumber = "4533787178994213";
const last4Digits = cardNumber.slice(-4);
console.log(last4Digits);
9 changes: 7 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
// const 12HourClockTime = "20:53";
// const 24hourClockTime = "08:53";

//the name of a variable can not start with a number

const twelveHourClockTime = "20:53";
const twenty4hourClockTime = "08:53";
8 changes: 7 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,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: Number(),replaceAll(),Number(),replaceAll(),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?
//line 5, there was no "," between arguments

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

// d) Identify all the lines that are variable declarations
//line1,line2,line7,line8

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
//it replaces "," from the carPrice with an empty string, basically deleting the commas, and then turning the string "10000"
// in to a number 10000
6 changes: 6 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,20 @@ 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?
//6 variable declarations

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

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
//% it's the remainder operator and it tells us how many seconds are left out of a whole minute

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
//total time in minutes without the remaining seconds

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

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
//it will work with all values as long as they are numbers,
27 changes: 23 additions & 4 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const penceString = "399p";
const penceString = "399p";

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

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); //399
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);
); //3

const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
Expand All @@ -25,3 +25,22 @@ 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
// ); : it creates a variable with the value "399" by eliminating the character at index penceString.length - 1

//3.const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");:initialises a string variable of at least 3 characters,
// if it has les than 3 characters it adds 0 to make up for it

//4.const pounds = paddedPenceNumberString.substring(
//0,
// paddedPenceNumberString.length - 2
// );:initialises a string variable with the value of paddedPenceNumberString except the last 2 characters

//5.const pence = paddedPenceNumberString
// .substring(paddedPenceNumberString.length - 2)
// .padEnd(2, "0");: takes the last 2 characters from paddedPenceNumberString , it has to be 2 characters long if not it will add a 0 for
// every missing character
//it adds a dot between pounds and pence and logs 3.99
3 changes: 3 additions & 0 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ What effect does calling the `alert` function have?
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?
It generates an input field

What is the return value of `prompt`?
whatever is introduced int hte input field
3 changes: 3 additions & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ Try also entering `typeof console`
Answer the following questions:

What does `console` store?
it stores properties

What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
the dot allows to access the properties of the object "console"
Loading