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
// Line 3 take the count and add 1 to that so as the count was 0 line 3 make it 1.
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 @@ -4,8 +4,9 @@ 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 = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0);

let initials = ``;
console.log(initials);

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

8 changes: 6 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,11 @@ 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 lastSlDotIndex = filePath.lastIndexOf(".");
Copy link
Contributor

Choose a reason for hiding this comment

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

In the variable name, lastSlDotIndex, what does Sl stand for?

Copy link
Author

Choose a reason for hiding this comment

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

I think it comes from Slice.

Copy link
Contributor

Choose a reason for hiding this comment

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

Variable names should be meaningful. What are you trying to describe as SlDot? Slice dot?

Copy link
Author

Choose a reason for hiding this comment

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

I would say it means the last slice after "."

const ext = filePath.slice(lastSlDotIndex);

console.log(`The dir part of ${filePath} is ${dir}`);
console.log(`The ext part of ${filePath} is ${ext}`);
// https://www.google.com/search?q=slice+mdn
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 @@ -7,3 +7,12 @@ 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);

// this will make a random number between 1-100. Math.random will give us a number between 0-1 (both ends included).
// (maximum - minimum + 1): this is equal to 100-1+1=100 in this example.
// (Math.random() * (maximum - minimum + 1)): this will multiply the random number which is between 0-1 by 100 so we have a number.
// Math.floor: this will round the number to the nearest lower whole number.
// + minimum: will add 1 (the defined minimum) to the number so it never be below 1.
// so we end up with a random number between 1-100
6 changes: 4 additions & 2 deletions 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?
// 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 need to add double "//" at the start of the line so computer will ignore this line.
4 changes: 3 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
// const age = 33; age should be defined as let so it can get different values.
let age = 33
age = age + 1;
console.log(age);
4 changes: 3 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?
// any variable must be defined first and then can be used.

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
// const cityOfBirth = "Bolton"; => Wrong place!
10 changes: 9 additions & 1 deletion 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 last4Digits = cardNumber.toString().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



//.Slice() is for strings but here we have 1 number here. so we need to make that number a string by putting it in a "". or using .toString() to change any input to string type.


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";

// An identifier or keyword cannot immediately follow a numeric literal.

const ClockTime24Hour = "20:53";
const ClockTime12hour = "08:53";
24 changes: 23 additions & 1 deletion Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,34 @@ 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
// a) How many function calls are there in this file? Write down all the lines where a function call is made

// lines 4,5,7,8
// the following 4 lines are functions as they are manipulating the data.
//carPrice = Number(carPrice.replaceAll(",", ""));
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ,""));
//const priceDifference = carPrice - priceAfterOneYear;
//const percentageChange = (priceDifference / carPrice) * 100;

// 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
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); the error is a missing comma between the two arguments in the .replaceAll() function call. Without the comma,
// the two string arguments "," and "" are not separated, so the computer reads them together as one argument.

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

// lines 4,5
//carPrice = Number(carPrice.replaceAll(",", ""));
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));

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


// d) Identify all the lines that are variable declarations

// lines 1,2,7,8

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
// It replace the "," with "" which means omitting the "," and add nothing so we have whole number form that computer can work with it.
13 changes: 13 additions & 0 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,26 @@ console.log(result);

// a) How many variable declarations are there in this program?

6

// b) How many function calls are there?

// 1 : console.log(result);

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

// % is the remainder. that line of code divides the total seconds number by 60 and gives us the remaining seconds.

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

// in this line, totalMinutes of the move calculated. the remainder will be deducted and the rest of the second divided by 60 gives us the total minutes number.


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

// it represents the move length in hour, minutes and seconds. and it would be better understood as duration.

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

// yes as long as it receives the total seconds as a whole number it works fine.
29 changes: 14 additions & 15 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
const penceString = "399p";

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

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

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

const pounds = paddedPenceNumberString.substring( 0 , paddedPenceNumberString.length - 2);
const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
console.log(`£${pounds}.${pence}`);

// This program takes a string representing a price in pence
Expand All @@ -25,3 +14,13 @@ 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): creates a new string with the last character removed by taking a substring from index 0 up to
// penceString.length - 1, it removes the trailing "p" so we are left with the numeric pence portion as a string.
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensures the numeric string has at least 3 characters by adding leading zeros if required.
// padStart(3, "0") will left-pad with "0" until the length is at least 3, so the code expects to split the string into ...pounds and last two digits = pence.
// By guaranteeing at least 3 characters, the substring operations that follow always have at least one digit for pounds and two for pence.
// 4. const pounds = paddedPenceNumberString.substring( 0 , paddedPenceNumberString.length - 2): takes the substring from the start up to the character two from the end.
// That is, everything except the last two characters. as the last two characters represent pence; everything before that is pounds. Splitting this way converts a string of
// pure pence into pounds and pence parts.
// 5. substring(paddedPenceNumberString.length - 2): takes the last two characters (the pence portion).
// 6. .padEnd(2, "0"): would add trailing zeros to make sure the pence string is at least 2 characters long.
4 changes: 3 additions & 1 deletion Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
"Hello world!" will be printed in a pop up box.

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 window with the question and a place to input answer is opening.
What is the return value of `prompt`?
The input value will be returned by prompt() and stored in the variable myName.
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the user entered a value and clicked the "Cancel" button (instead of the "OK" button)?

Copy link
Author

Choose a reason for hiding this comment

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

The return value will be null for myName. meaning that no input.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by "no input"?
What would prompt() return if the user didn't enter anything (i.e., no input) and then click "OK"?

Copy link
Author

Choose a reason for hiding this comment

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

The return will be null

Copy link
Author

Choose a reason for hiding this comment

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

null means no value entered.

Copy link
Contributor

Choose a reason for hiding this comment

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

What would prompt() return if the user didn't enter anything (i.e., no input) and then click "OK"?

Have you verified that prompt() returns null in this case? Because I got a different result.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. If cancel be clicked, the output will be null. If no value entered and OK be clicked the output will be nothing as ``.

24 changes: 15 additions & 9 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
## Objects

In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course.
//In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course.

Open the Chrome devtools Console, type in `console.log` and then hit enter
//Open the Chrome devtools Console, type in `console.log` and then hit enter

What output do you get?
// What output do you get?
// ƒ (){for(var o=arguments.length,u=new Array(o),l=0;l<o;l++)u[l]=arguments[l];if(e.apply(n,u),!("assert"===r&&u[0]||a)){a=!0;try{var
// d=Di.parse(new Error).map((t=>t.toString())).splice(1),c=("assert"===…

Now enter just `console` in the Console, what output do you get back?
//Now enter just `console` in the Console, what output do you get back?
// console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}

Try also entering `typeof console`
//Try also entering `typeof console`
//Answer the following questions:
//What does `console` store?
//The console in JavaScript doesn’t store the program’s variables or data — instead, it’s an object provided by the browser (or Node.js) that contains a set of methods for
//logging information, debugging, and interacting with the JavaScript environment.

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 the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
//In both cases, console is an object, and log or assert are properties (specifically, methods) of that object. The dot (.) is called the dot notation operator or member
//access operator. It is used in JavaScript (and many other languages) to access a property or method that belongs to an object.