Skip to content
4 changes: 4 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,7 @@ 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

Answer:

//Line 3 is assignment statement,its taking the current value to count,then make the count to a new value.
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 = ``;
Answer:
let initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0);

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

8 changes: 5 additions & 3 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ 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 = ;
Anwer:
const dir = filePath.slice(0, lastSlashIndex);
const ext = base.slice(lastDotIndex + 1);
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
13 changes: 13 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,16 @@ 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

Answer:

//num is a random number between 1 and 100.

//Math.random() makes a number between 0 and 1.

//times (maximum - minimum + 1) makes it bigger.

//Math.floor cuts off the decimal.

//+ minimum makes sure the random number starts at 1 instead of 0

6 changes: 5 additions & 1 deletion Sprint-1/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
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?

Answer:
//We can turn those lines into comments by putting // at the start.
//Then computer ignores them but humans can still read/see them.
7 changes: 7 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,10 @@

const age = 33;
age = age + 1;

Answer:

//This gives an error because we used const, which can't be changed.
// If we want to update the value, we should use let instead of const.
let age = 33;
age = age + 1;
9 changes: 9 additions & 0 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@

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


Answer:

//Error because cityOfBirth is used before it is declared.
//We need to define the variable first, then use it.

const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
9 changes: 9 additions & 0 deletions Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ 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

Answer:

//I guessed it breaks because slice is for strings but cardNumber is a number.
//When I try it, the error says slice is not a function (so I was right).
//Fix: change the number to string first, then slice works.
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.toString().slice(-4);
console.log(last4Digits); // 4213
10 changes: 9 additions & 1 deletion Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";


Answer:

// The first line is wrong cuz variable names can't start with a number.
// We should rename it like hour12ClockTime or something that doesn't start with a digit.
const hour12ClockTime = "20:53";
const hour24ClockTime = "08:53";
15 changes: 15 additions & 0 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,26 @@ 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
carPrice = Number(carPrice.replaceAll(",", ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
console.log(`The percentage change is ${percentageChange}`);


// 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?
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
fix;
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));

// c) Identify all the lines that are variable reassignment statements
carPrice = Number(carPrice.replaceAll(",", ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));

// d) Identify all the lines that are variable declarations
let carPrice = "10,000";
let priceAfterOneYear = "8,543";

Choose a reason for hiding this comment

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

These are correct - are there any other declarations?

Copy link
Author

Choose a reason for hiding this comment

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

Hi thanks for your review. I added missing const variable declarations. Thanks



// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
replaceAll gets rid of the commas → "10,000" becomes "10000".
Number() turns that string into the number 10000.
so we can do maths with it.
7 changes: 7 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,21 @@ 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: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result.

// b) How many function calls are there?
Only 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
% gives the leftover after dividing, so movieLength % 60 = extra seconds

// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
(movieLength - remainingSeconds)/60 → takes away seconds, then gets whole minutes


// e) What do you think the variable result represents? Can you think of a better name for this variable?
It’s the time of the movie written as hours:minutes:seconds. A better name could be movieTime or formattedTime.

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
works for normal numbers, but long movies or single-digit mins/secs look weird
9 changes: 9 additions & 0 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
const penceString = "399p";
sets the price string with "p" at the end


const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);
//removes the p from the end


const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);
// makes sure it has at least 3 digits, adds 0 at start if needed


const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
// takes last 2 digits → pence, adds 0 at end if needed

console.log(`£${pounds}.${pence}`);
// prints the price in pounds like £3.99


// This program takes a string representing a price in pence
// The program then builds up a string representing the price in pounds
Expand Down
4 changes: 4 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,12 @@ In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
*It shows a popup message on the screen.*

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?
*pops up a box asking you to type something*

What is the return value of `prompt`?
*whatever the user typed (as a string)*
4 changes: 4 additions & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ Open the Chrome devtools Console, type in `console.log` and then hit enter
What output do you get?

Now enter just `console` in the Console, what output do you get back?
*shows a big list of all the stuff it can do, like log, assert, and other functions*

Try also entering `typeof console`

Answer the following questions:

What does `console` store?
*console stores all the console functions you can use.*

What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
*the . means “use a function from console.*