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: 3 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,8 @@ let count = 0;

count = count + 1;

// line basically modifies the variable count by updating and adding 1 to it. So basically count is now equal to the current count + 1. In this instance 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
3 changes: 2 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,8 @@ 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

9 changes: 6 additions & 3 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
console.log(`The base part of ${filePath} is ${base}`);
console.log(lastSlashIndex)
console.log(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(4,8);
console.log(ext)
console.log(dir)
// https://www.google.com/search?q=slice+mdn
18 changes: 17 additions & 1 deletion Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@ const minimum = 1;
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?
// 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

//ANSWER
// num represents random whole numbers between 1 and 100

// Math.floor is a built in function in JavaScript which basically rounds down a number to
// its nearest whole integer.

//Math.random is also a built in function for selecting random numbers in this case
//numbers that are between 1 and 100

//Therefore num is equal to the a randomly selected number that has been
// rounded down to its nearest whole integer times (maximum - minimum + 1) + minimum
//the computer solves the expression in the bracket first as per mathematics order of operation
// rules so the expression shrinks to Math.floor(math.random()*100) + 1)
// so whatever the random value that the computer generates will be multiplied by 100 and rounded
// or floored down to it's nearest whole integer plush1
7 changes: 5 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
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?

// This is a a syntax error. This text is supposed to be commented out in order for us to not run into this error
// we should add // so that the computer doesn't try to run this text as code .

5 changes: 4 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 33;
age = age + 1;

// the variable age has been declared as constant in order to fix this age will
// need to be declared using let so that it's values can be reassigned
7 changes: 5 additions & 2 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// 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 variable city of birth needs to be declared first before attempting to
// print the string
7 changes: 6 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const cardNumber = 4533787178994213;
const cardNumber = "4533787178994213";
const last4Digits = cardNumber.slice(-4);

// The last4Digits variable should store the last 4 digits of cardNumber
Expand All @@ -7,3 +7,8 @@ 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

//Prediction the cardNumber is not a string since it is not in "" so I don't
// think the slice() function will work

// After running the code I got a TypeError
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 = "8:53pm";
const 24hourClockTime = "20:53";
const TwelveHourClockTime = "8:53pm";
const TwentyFourHourClockTime = "20:53";
17 changes: 16 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,8 @@ let carPrice = "10,000";
let priceAfterOneYear = "8,543";

carPrice = Number(carPrice.replaceAll(",", ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
// console.log(carPrice)
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));

const priceDifference = carPrice - priceAfterOneYear;
const percentageChange = (priceDifference / carPrice) * 100;
Expand All @@ -20,3 +21,17 @@ console.log(`The percentage change is ${percentageChange}`);
// d) Identify all the lines that are variable declarations

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?



// a) There are 2 function calls in this code. replaceAll() in line 4 and 5 and console.log() in line 10

// b) There is a SyntaxError on line 5. The replaceAll() function takes 2 arguments
// and this is missing a comma between the 2 arguments

//c) line 4 & 5

// d) line 1,2 7 & 8

// e) It is replaces the comma "," in carPrice and removes any spaces so
// everything becomes one string
17 changes: 16 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 = 10652; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -23,3 +23,18 @@ console.log(result);
// e) What do you think the variable result represents? Can you think of a better name for this variable?

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer

// Answers

// a) 6

// b) One function call is on this code - console.log() in line 10.

// c) The remainder (%) operator returns the remainder left over when one operand is divided by a second
// operand. It always takes the sign of the dividend.

// d) In line 4 the totalHours is calculated by subtracting the remainingMinutes from the totalMinutes and then dividing that answer by 60

// e) It is a string representing the time movie time in hours, minutes and seconds

// f) yes, because the variables for calculating the results use a formulas that will work with any number that is assigned to the movieLength variable
31 changes: 30 additions & 1 deletion Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);
// console.log(penceStringWithoutTrailingP);

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

const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");

// console.log(pence)
console.log(`£${pounds}.${pence}`);

// This program takes a string representing a price in pence
Expand All @@ -24,4 +27,30 @@ console.log(`£${pounds}.${pence}`);
// Try and describe the purpose / rationale behind each step

// To begin, we can start with

// Answers
// 1. const penceString = "399p": initialises a string variable with the value "399p"
// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length-1): this
// variable creates a new string that cuts the penceSting to 399,so it basically creates a new
// string from index 0, and removes the last index
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); this variable sets
// the penceStringWithoutTrailingP string length to 3, and if the length is shorter than 3 it adds
// "0" in front.
// 4. const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2)
// this variable uses the subString function to further slice the paddedPenceNumberString
// string on from the first index and remove the last 2 parts of in. In this case the string goes
// from '399' to just '3'

// 5.const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
// this variable creates a new string from the paddedPenceNumberString variable using the subString
// function. This time it creates a new string from the last 2 indexes. Furthermore it sets the target
// length for this new variable to 2 and if is is less than 2 it sets a condition to add
// a "0" at the end by using the padEnd() function


//6. console.log(`£${pounds}.${pence}`); this is a function call that displays the final amount in
// pounds. It uses string interpolation to directly use the variable values pound and pence and also
// formats the string by adding £ before the values. So the output displayed will be £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 @@ -11,8 +11,11 @@ In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
I get a pop up message that says chrome://new-tab-page-third-party says Hello,World!

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?
I get a pop up message on my screen that says "what is your name?" and it allows me to enter my name.
What is the return value of `prompt`?
It returns the name that I type, Asanda
5 changes: 5 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,17 @@ 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?
f log(){[native code]}

Now enter just `console` in the Console, what output do you get back?

console{debug:f,error:f, info:f, log:f, warn:f,...} and a list of other functions

Try also entering `typeof console`

Answer the following questions:

What does `console` store?
It stores the object
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
the "." is an access operator which allows you to access the log or assert method.
Loading