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
6 changes: 4 additions & 2 deletions Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ let count = 0;

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 1 makes box called count and puts 0 inside it.
// line 3 adds 1 to count.
//Line 3 is an increment operation because it increases the value of the variable count by 1.

3 changes: 1 addition & 2 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 = ``;
let initials = firstName[0] + middleName[0] + lastName[0];

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

5 changes: 3 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,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 dir = ;
const ext = ;
const dir = filePath.slice(0, lastSlashIndex)
const lastDotIndex = base.lastIndexOf(".");
const ext = filePath.slice(lastDotIndex + 1);

// https://www.google.com/search?q=slice+mdn
3 changes: 3 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,6 @@ 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 is random whole number between 1 and 100.
//each time the program runs, it creates a different number in that range.
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?


// We can add // at the start of the lines to turn them into comments.
// The computer ignores comments, so it will not run them.
5 changes: 5 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,8 @@

const age = 33;
age = age + 1;

// The error happens because age was declared using const.
// const variable canot be changed.
// We trying to change age ,so casue error.
// It should use let instead.
5 changes: 5 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,8 @@

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

// The error happens because cityOfBirth is used before it is declared.
// Const variable cannot be used before declaration.
// Move the variable delaration before the console.log line.

6 changes: 6 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,9 @@ 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


// The code will not work because slice() cannot be used on numbers.
// Slice() only works on strings or arrays.
//We need to convert the number to string first
const last4Digits = cardNumber.toString().slice(-4);
8 changes: 7 additions & 1 deletion Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";

// Variables names cannot start with a number.
// Rename the variables so they start with a letter.
const hour12ClockTime = "20:35";
const hour24ClockTime = "08:35";

23 changes: 22 additions & 1 deletion Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let carPrice = "10,000";
let priceAfterOneYear = "8,543";

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

const priceDifference = carPrice - priceAfterOneYear;
const percentageChange = (priceDifference / carPrice) * 100;
Expand All @@ -12,11 +12,32 @@ 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 4 function calls in this file.
carPrice.replaceAll(",", "")
priceAfterOneYear.replaceAll(",", "")
Number(carPrice.replaceAll(",", ""))
Number(priceAfterOneYear.replaceAll(",", ""))


// 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 comin from this line

priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
// The error happens because a comma is missing between the arguments in the replaceAll() function.
// The correct line should be
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));

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

// d) Identify all the lines that are variable declarations
let carPrice = 10,000";
let priceAfterOneYear = "8,543";
const priceDifference = carPrice - priceAfterOneyear;
const percentageChange = (priceDifference / carPrice) * 100;


// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
Number(carPrice.replaceAll(",", ""))
// It removes commas from the number string and converts the results into a real number so calculation can be done.
21 changes: 21 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,35 @@ 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.
movieLength
remainingSeconds
totalMinutes
remainingMinutes
totalHours
result

// b) How many function calls are there?
There is 1 function call in this program.
console.log(result)
// The function call is on line 10, where we are calling the console.log function to print the value of result to the console.

// 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 after dividing movielenth by 60. It gives us the number of seconds that are left over after we have taken out all the whole minutes from the movie length



// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
// first remove the extra seconds.
// then divide by 60 to get the total number of minutes in the movie length.

// e) What do you think the variable result represents? Can you think of a better name for this variable?
// The variable result represents the formatted time in hours:minutes:seconds format.
// A better name for this varibale could be formattedTime.

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// no, this code will not work good for all values of movielength.
// it will only right for postitive whole number of seconds.
// if movieLength is nagatuve or not a whole number, the result will not be right.
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"
// 2.Removes the "p" at the end, leaving "399".
// 3. Makes sure the number has at least 3 digits .
// 4, takes the first part as pounds.
// 5. Takes the last two digits as pence.
// 6. Prints the price in punds format ( for example, £3.99).
6 changes: 6 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,14 @@ 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 in the browser with the "Hello
world!".
// Then I must clicks ok to close it.

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?
//Its shows a popup with text box where user can type something.
What is the return value of `prompt`?
//It returns the text the user types.
//If the user clicks Cancel, it returns null.
13 changes: 12 additions & 1 deletion Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ 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?
// It shows that consel.log is function.

Now enter just `console` in the Console, what output do you get back?
// shows an object with many function inside it (like,error)

Try also entering `typeof console`
//It resturn objects.

Answer the following questions:

What does `console` store?
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
// conseole store an object.
// This object contains many functions used for priniting message and debugging.

What does the syntax `console.log` or `console.assert` mean?
// It means we ar using something inside the consel object.
In particular, what does the `.` mean?
// The dots is used to access something inside an objects.
//For example ,console.log means:
// Go inside the console object and use the log function.