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 adds 1 to 'count'
// The = operator gives the new value to 'count'.
5 changes: 2 additions & 3 deletions Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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 = ``;

// https://www.google.com/search?q=get+first+character+of+string+mdn
let initials = firstName[0] + middleName[0] + lastName[0];

// https://www.google.com/search?q=get+first+character+of+string+mdn
5 changes: 2 additions & 3 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ 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);
const ext = filePath.slice(filePath.lastIndexOf("."));
// https://www.google.com/search?q=slice+mdn
4 changes: 4 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,7 @@ 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
// num represents a random number between minimum and maximum.
// Math.random() generates a random number , and Math.floor() rounds it down to a whole number.
// Expression (maximum-minimum+1) gives the range of numbers between minimum and maximum.
// On the final line, on the random number will add the minimum value , and that's ensure that the random number is always between minimum and maximum.
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?
SyntaxError: Unexpected identifier 'is'. JavaScript tries to read the text as code, but it is not valid.
Add // at the beginning of each line make them comments.
Comment on lines 1 to +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.

Brilliant explanation. Can we apply the fix to line 1, and 2?

2 changes: 2 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,5 @@

const age = 33;
age = age + 1;
// The above code has a TypeError:Assignment to constant variable.
//The error is because age is declared as a constant variable, which mean cannot be reassigned. To fix this error, we can declare age as a let variable instead.
Comment on lines +5 to +6

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!
Can we apply the fix to line 3?

1 change: 1 addition & 0 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
// The error is a ReferenceError: Cannot access 'cityOfBirth' before initialization. The error happens because cityOfBirth is used before it is declared. We can fix this error by moving the const cityOfBirth line before console.log().

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!
Can we apply the fix to the file?

2 changes: 2 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,5 @@ 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
// I think the code won't work because the slice() works only on strings, and cardNumber is a number.
// The error says that slice() its not a function because cardNumber is a number. Converting it to a string("4533787178994213") will fix the problem.
Comment on lines +10 to +11

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!
Can we apply the fix to file?

1 change: 1 addition & 0 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
const 12HourClockTime = "8:53pm";
const 24hourClockTime = "20:53";
// SyntaxError:Invalid or unexpected token. This error is because the variable name starts with a number. Variable name cannot start with a number in JavaScript.We can fix the error by using a valid variable const twelveHourClockTime.

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 as well.
Can we apply the fix to the file?

9 changes: 5 additions & 4 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,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

// There are 5 function calls in this file. The function calls are made on the following lines: replaceAll() line 4, Number() line 4, replaceAll() line 5, Number() line 5, console.log() line 10.
// 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 coming from line 5. The error appears because there is a missing comma in the replaceAll() function. We can fix the problem by adding a comma in the replaceAll() function on line 5.
// c) Identify all the lines that are variable reassignment statements

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

// The variable declarations are on line 1, line 2, line 7 and line 8.
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
//The expression removes the comma from the string from carPrice and converts the string to a number.
Comment on lines 14 to +23

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Brillant explanation!
One small comment is, you're expected to fix the error in line 5.

11 changes: 6 additions & 5 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,15 @@ 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?

// There are 6 variable declarations in this program.
// b) How many function calls are there?

// There is just 1 function call.
// 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 represents the remaining seconds after dividing the movie length by 60.
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

// The expression calculates the total number of whole minutes by removing the remaining seconds and dividing by 60.
// e) What do you think the variable result represents? Can you think of a better name for this variable?

// The variable result represents the movie length in hours, minutes and seconds. A better name could be movieDuration because its clearly describes what the variable are.
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// The code works for positive numbers because it converts the movie length from seconds into hours, minutes and seconds. It does not work correctly for negative values or values that are not numbers.
Comment on lines 14 to +26

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Lovely explanations!

5 changes: 5 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,8 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
// Uses substring() to create a new string without the las character. length-1 finds the position before the final "p", so the result is "399". Thats mean its removing the "p" and leave only numeric value.
// Uses padStart(3,"0") to ensure the string has at least 3 characters by adding zeros at the beginning if needed. In our example the string has already 3 characters ("399") so it does not change.
// Use substring() to extract the pounds by taking all characters expect the last two digit.
// Use substring() to extract the last two characters as pence, and the use padEnd() to ensure the pence value always has two digits.
// Finally, using the console.log() to display the final price in pounds and pence format.
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?
// The alert function displays a pop-up message on the screen with the message "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?
What is the return value of `prompt`?

// The 'prompt' function shows a pop-up that asks users to enter some text.The prompt() function return the text entered by the user. In my case its returned "Alexandra" and stored it in the myName variable.
1 change: 1 addition & 0 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Answer the following questions:

What does `console` store?
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
// Console stores an object containing different methods such as log(), error(), warn() and assert(). The dot(.) is used to access a property of an object. Console.log access the log method, and the console.assert access the assert method of the console.
Loading