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
2 changes: 2 additions & 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,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

// Line 3 is taking the value of count, then adding 1 to that value, then making that new value to be the current count.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apart from count = count + 1, can you look for more compact operation to increment variable by 1.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

could it be:
Let count = 0+1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No the are other approaches, when the requirement is to increase/decrease the value of a number only by 1.

You can go through this - increase-or-decrease-a-number-by-one

2 changes: 1 addition & 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,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];

// 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 +1);
const ext = filePath.slice (filePath.lastIndexOf ("."));

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

// From what I can work out, it is generations a random number between 2 and 100 for the value of num.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Math.random() generates random number [0,1) i.e from 0 (including) to 1 (excluding).

Now can you think what will be the value of num, when random number generated is zero.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

from 0 to 1, mostly through decimals

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Think like this

Math.random() generates value in the range [0,1) where 0 is included and 1 is excluded.

Since, maximum - minimum + 1 = 100

Then Math.random()*(100) will provide value in the range [0,100) . Note thatsquare bracket [ or ]means included and normal bracket ( or ) means excluded.

Math.floor(N) - this function provide number greatest integer less than or equal to N

So for this line of code Math.floor(Math.random()*(100)), the number generate will be in the range [0,99] .

Adding minimum makes the range of variable num to [1,100] i.e. increasing the previous range by the value of 1.

// math.floor ensures the number is a whole number without decibils. (maximum - minimu +1) is (100 - 1 + 1)=100.
// Math.random pics a random number from 0 to 1 with two decibils, such as 2.13.
// The Order they follow is: Match.random multiplied by (Maximum - minimum + 1), then add minimum of 1.
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?
*/
2 changes: 1 addition & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 33;
age = age + 1;
3 changes: 2 additions & 1 deletion 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 ?

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

what do you think, why it was not working before ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah the order of them in line of code was wrong, const needs to be before the console.log.

19 changes: 12 additions & 7 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const cardNumber = 4533787178994213;
const cardNumber = "4533787178994213";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is correct but can you think of a way to convert a number to string using some js functions and use that to get the last 4 digit.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

.toString wold work best I belive:
const cardNumber = 45334533787178994213;
let cardString = cardNumber.toString();
return last4Digits = cardString.length -4

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here the last line would be like this :

cardString.slice(cardString.length-4)

const last4Digits = cardNumber.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
/*
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
I firsth thought the -4 would not work as it starts on 0
I then recalled the code wont work as the cardNumber is a number and not a string, it needs to be a string for the .slice to work.
*/
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 _12HourClockTime = "8:53pm";
const _24hourClockTime = "20:53";
10 changes: 10 additions & 0 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ 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 5 calls made:
carPrice = Number(carPrice.replaceAll(",", ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""))
b) Error on line 5 for "," it is missing the seperating , between "," and "".
c) 4 and 5
d) 1 and 2, 7 and 8,
e) It removes the , from the string and replaces it with nothing. Used to help change the string into a number with the "Number" function.
*/
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 @@ -23,3 +23,13 @@ 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

/*
a) There are 6: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result.
b) There is one: console.log.
c) It is taking the movieLength and doing a remainder that is showing what is left after the vaule has been divided, in this case wil be 84.
I found the info here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder
d) It is removing any extra seconds from the division by 60 so that is is showing as whole numbers without decimals.
e) Result is showing the movies duration but broken down to hours:minutes:seconds, I think it should be movieDuration to help describe it better.
f) Yes, it does work to show the lenght even if it is only in one section, though it does show values of 0, could clean it up to show nothing.
*/
8 changes: 8 additions & 0 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
/*
3-6. It is taking the vaule from pencestring and using substring to return part of the string, by -1 so from the end resualting in "399"
8. It is now adding "0" infront of vaule if the vaule is under 3 characters in size.
9-12. Using the substring function to reduce the size of the vaule to just 2 characters.
14-16. Taking the value from paddedPenceNumberString and this time with substring, only showing the last 2 characters in teh value.
Then with using .padEnd it ensures that 2 characters are shown with 0 being there is nothing is there.
18. howing the resualt of the code starting with a "£" then the value of "pounds" then a "." and lastly value of "pence"
*/
Loading