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-2/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 is updating the value of the count variable by adding 1 to the current value of count. The = operator is used to assign the new value (count + 1) back to the count variable, effectively incrementing its value by 1.
2 changes: 1 addition & 1 deletion Sprint-2/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ const 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.

const initials = ``;
const initials = firstName[0] + middleName[0] + lastName[0]; // the expected output is "CKJ"

// https://www.google.com/search?q=get+first+character+of+string+mdn
8 changes: 4 additions & 4 deletions Sprint-2/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ 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 lastDotIndex = base.lastIndexOf(".");
const dir = filePath.slice(0, lastSlashIndex);
const ext = base.slice(lastDotIndex + 1, base.length);

const dir = ;
const ext = ;

// https://www.google.com/search?q=slice+mdn
// https://www.google.com/search?q=slice+mdn
2 changes: 2 additions & 0 deletions Sprint-2/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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 is a random integer between the minimum and maximum values (inclusive) and is a calculated value from this clearly explained expression below.
// Try breaking down the expression and using documentation to explain what it means
/*The expresssion Math.random() generates a random floating-point number between 0 (inclusive) and 1 (inclusive). By multiplying this value by (maximum - minimum + 1), we scale it to the desired range. The Math.floor() function is then used to round down to the nearest whole number, and finally, we add the minimum value to shift the range to start from the minimum value instead of 0. The expected result is always a whole number between the minimum of 1 and the maximum of 101 (inclusive).*/
// 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
5 changes: 3 additions & 2 deletions Sprint-2/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?
// by commenting out these two lines using // for single-line comments or /* */ for multi-line comments, we can prevent the computer from running them while still keeping the instructions visible for human readers or developers who may be reviewing the code.//
//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?//
5 changes: 4 additions & 1 deletion Sprint-2/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;

or;
age += 1;
5 changes: 5 additions & 0 deletions Sprint-2/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
// because we are trying to use the variable cityOfBirth before it has been declared and assigned a value.

//here's the corrected code://
//const cityOfBirth = "Bolton";//
//console.log(`I was born in ${cityOfBirth}`);//
6 changes: 6 additions & 0 deletions Sprint-2/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ 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
// This will result in an error because the slice method is not defined for numbers. To fix this, we need to convert the cardNumber variable to a string before calling the slice method on it.
// 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

//here is the corrected code://
/*const cardNumber = "4533787178994213";
const last4Digits = cardNumber.slice(-4);
*/
4 changes: 4 additions & 0 deletions Sprint-2/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
const 12HourClockTime = "8:53pm";
const 24hourClockTime = "20:53";
// this will result in an error because variable names cannot start with a number. To fix this, we can rename the variables to start with a letter or an underscore. For this reason, we can change the variable names to something like hour12ClockTime and hour24ClockTime. This will make the variable names valid and prevent the error from occurring.
//here is the corrected code://
/*const hour12ClockTime = "8:53pm";
const hour24ClockTime = "20:53";*/
9 changes: 5 additions & 4 deletions Sprint-2/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ 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(",", ""), replaceAll("," ""), Number(...), 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?

// The error is occurring on line 5 because there is a missing comma in the replaceAll method. The correct syntax should be replaceAll(",", "").
// c) Identify all the lines that are variable reassignment statements

// 2 variable reassignment statements: line 4 and line 5
// d) Identify all the lines that are variable declarations

// 4 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?
// The expression Number(carPrice.replaceAll(",", "")) is first using the replaceAll method to remove all commas from the carPrice string, resulting in a string that represents a number without any formatting. Then, the Number function is used to convert that string into a numeric value. The purpose of this expression is to convert the formatted string representation of the car price into a usable numeric value for calculations.
41 changes: 37 additions & 4 deletions Sprint-2/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,47 @@ 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: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result
// b) How many function calls are there?

// only one function call: 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
// The expression movieLength % 60 calculates the remainder of the division of movieLength by 60, which gives the number of seconds remaining after converting the total length of the movie from seconds to minutes.

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

// line 4 calculates the total number of minutes in the movie by subtracting the remaining seconds from the total movie length in seconds and then dividing that value by 60, thus converting the total length of the movie from seconds to minutes.
// e) What do you think the variable result represents? Can you think of a better name for this variable?

// The variable result represents the total length of the movie in hours, minutes, and seconds format. A better name for this variable could be movieDuration or formattedMovieLength, as it more clearly describes the purpose of the variable.
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
/* for positive integers:movieLength = 8784 → 2:26:24

movieLength = 60 → 0:1:0

movieLength = 3599 → 0:59:59

movieLength = 0 → 0:0:0

for negative integers: movieLength = -60 -> -1:59:0
movieLength = -3599 -> -1:0:1
movieLength = -8784 -> -3:33:36
it works for negative integers as well, but the output may not be meaningful or should have validation to prevent negative values.

for non-integer values or decimal values: movieLength = 60.5 → 0:1:0.5
movieLength = 3599.9 → 0:59:59.9
movieLength = 8784.7 → 2:26:24.7
it works for non-integer values as well, but the output may not be meaningful or should have validation to prevent non-integer values.

for non-numeric values: movieLength = "abc" → NaN:NaN:NaN
movieLength = null → 0:0:0
movielength = undefined → NaN:NaN:NaN
it doesn't work for non-numeric values.

for very large values: movieLength = 1000000000 → 277777:46:40
movieLength = 1000000000000 → 277777777:46:40
it works for very Large values as well, but the output may not be meaningful or should have validation to prevent very Large values.

for very small values: movieLength = 0.0001 → 0:0:0
movieLength = -0.0001 → 0:0:0
movieLength = 0.0000001 → 0:0:0
it works for very small values as well, but the output may not be meaningful or should have validation to prevent very small values.

4 changes: 2 additions & 2 deletions Sprint-2/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ const penceString = "399p";

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

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

const pence = paddedPenceNumberString
Expand Down
4 changes: 3 additions & 1 deletion Sprint-2/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ Let's try an example.
In the Chrome console, invoke the function `alert` with one argument, the string `"Hello world!"`;

What effect does calling the `alert` function have?

a pop-up box with a message of HELLO WORLD on the window
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?
the effect propmt displayed on the window is a pop-up box with an empty field to fill and with the string on top of it and when a user filled the field in. The filled in value gets displayed on the console.
What is the return value of `prompt`?
// the return value of the prompt as explained above is the answer or the value the user puts in the prompted field on the window.
9 changes: 6 additions & 3 deletions Sprint-2/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ 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?

ƒ log() { [native code] }
Now enter just `console` in the Console, what output do you get back?

with a dropdown menu icon next to console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}
Try also entering `typeof console`

'object'
Answer the following questions:

What does `console` store?
console is a regular javascript object provided by the browser or node and stores functions and/or properties.
As the dot next to it is a property accessor on an object, console is an object that is built to store functions.
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
The "." is a property access on the object and means get something inside this object.
Loading