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
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
/*
In line 3, it firstly execute count + 1 i.e 1 and then new value of count is store into variable count.
The value of count is initially 0 and then in line three it added by 1 so new value of count becomes 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 @@ -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 = ``;
let initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0);
console.log(initials);

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

12 changes: 10 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,15 @@ 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 lastindex1 = filePath.lastIndexOf("/");
const dir1 = filePath.slice(0,lastindex1);
console.log(`The variable contains directory path of a file: ${dir1}`);
const dir = filePath.slice(0,44);
console.log(`This variable stores directory path of a file: ${dir}`);
//I did from both ways just to clear my concepts.

const lastext = filePath.lastIndexOf("/");
const ext = filePath.slice(lastext+5);
console.log(`This is extension part of a file: ${ext}`);

// https://www.google.com/search?q=slice+mdn
8 changes: 8 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ const minimum = 1;
const maximum = 100;

const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
console.log(num);

// In this exercise, you will need to work out what num represents?
// 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

/*
The num is a variable that hold a random variable every time we run the code it gives us a different random number.
In the above expression, firstly it will solve the parenthesis part i.e maximum - minimum +1.
i.e, (100 - 1 +1)-> 100 then it will evaluate Math.random, Math.random generate any number from 0-1 and it will multiply by
100 and added by minimum value i.e 1. Math.floor makes the value round if it is in decimal.
*/
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?

//As age was constant there we can't change the value of age like this. I made age let so it can change the value of age.
7 changes: 6 additions & 1 deletion Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
let age = 33;
age = age + 1;
console.log(age);

/*As age was constant here we can't change the value of age like this.
because in line 4, the value of age is incremented by 1 and assigning again to age but if variable is const we can't change.
I made age let so I can change the value of age.*/
12 changes: 10 additions & 2 deletions Sprint-1/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?

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

/*
It a reference error, we cannot access cityOfBirth before initializing it. We are trying to fetch a
value of cityOfbirth without declaring it. The interpreter first runs the line 1 i.e console.log one
and try to find a value but its not declare and it will give a error. Though we have declare is in line 2
but js is an interpreted language that interpret line by line and runs the code.
The cityOfBirth is in locked state right now js couldn't access until reaches to it.
Right now it is in temporal locked state.
*/
17 changes: 16 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
const cardNumber = 4533787178994213;
const cardNumber = "4533787178994213";
const last4Digits = cardNumber.slice(-4);
console.log(last4Digits);

//const cardNumber = 4533787178994213;
//const lastdig = cardNumber.toString().slice(-4);
//console.log(lastdig);

// 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 a string method we are using it on number.
We can convert the number into string and then apply slice() method to retrieve last four digits or simply we
can declare number as a string using quotes.
Run a code : It gives TypeError and js gives this error when method/operation isn't valid for particular data
type using.
I got the idea of data type that slice() method can't use for this data type.
I attempt it by both ways I mentioned above.
*/
8 changes: 6 additions & 2 deletions Sprint-1/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";
const HourClockTime12 = "8:53pm";
const hourClockTime24 = "20:53";

/*The variable name cannot start with number. It can begin with _, $ or a letter.
I fixed it by renaming the variable names.
*/
15 changes: 14 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,24 @@ 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
/*
replaceAl() : In line 4, replaceAll(",", "") and in line 5, replaceAll("," "")
Number() : In line 4, Number(carPrice.replaceAll(",", "")) and in line 5, Number(priceAfterOneYear.replaceAll("," "")
console.log: In line 10, 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?
//Basically, the error is coming from line 5. It missed the , between two values.
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," , ""));

// c) Identify all the lines that are variable reassignment statements
//line 4 and line 5

// d) Identify all the lines that are variable declarations
//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?
/* Number(carPrice.replaceAll(",","")) let's breakdown this to understand.
carPrice.replaceAll(",","") -> replaces , and it becomes 1000
Number("1000") converts string to a number -> 1000.
*/
15 changes: 11 additions & 4 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const movieLength = 8784; // length of movie in seconds

//const movieLength = 8784; // length of movie in seconds
const movieLength = 9893;
const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;

Expand All @@ -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?
//six

// b) How many function calls are there?
// 1 i.e console.log

// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
// This is a reminder operator. It divides one number by another and gives a reminder.

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

/* const totalMinutes = (movieLength - remainingSeconds) / 60
Firstly it will evaluate bracket i.e (movieLength - remainingSeconds) and then divide the value by 60.
*/
// e) What do you think the variable result represents? Can you think of a better name for this variable?

// The result represents the how long the movie is, in hours, minutes and seconds. It can named as MovieDuration.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does"MovieDuration" make enough of a distinction to the other variable name called "movieLength"?

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
// Yes, I changed the value of movieLength and it worked. The movieLength is the variable used in calculating other
// values and to evaluate the total length of movie.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It may work without errors, but are there any possible inputs where the output doesn't look quite right?

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

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
/*line 3-6.
const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
) : calculate the length and then subtract 1,length is 4-1=3 , and extract substring 0 to 3 i.e 399

line 8.Padstart puts zero in beginning until it meets the desire length. The length is 3 and string length is already 3, so it remained unchanged.
paddedPenceNumberString = "399"

line 9-12.
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
); paddedPenceNumberString.length - 2: 3-2=1 -> paddedPenceNumberString.substring(0,1)-> pounds="3"
l
ine 14-16.
const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
(paddedPenceNumberString.length - 2)-> 3-2 = 1 -> substring(1).padEnd(2,"0")-> 99, the length is already two.
pence ="99"

line 18.
console.log(`£${pounds}.${pence}`);
£3.99
*/
11 changes: 6 additions & 5 deletions Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ Just like the Node REPL, you can input JavaScript code into the Console tab and
Let's try an example.

In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;
invoke the function `alert` with an input string of `"Hello world!"`; it displays hello world in a alert box

What effect does calling the `alert` function have?
What effect does calling the `alert` function have? the alert function forces browser to display a message or a warning.

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`?
Prompt("what is your name?"), it pops-up a dialog box where I enter my name.
I saved my name in a variable myName and I called the prompt function, it gives my name.
What effect does calling the `prompt` function have? by prompt you can write/give your input or user can cancel it
What is the return value of `prompt`? name user have input or null in case of cancel.
10 changes: 7 additions & 3 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ 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?
What output do you get? -> it says there a function log inside console.

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? it says there a function log inside console.

Try also entering `typeof console`
Try also entering `typeof console` ->object, console is a built-in object.

Answer the following questions:

What does `console` store?
It doesn't store anything, It is a debugging object that enables you to interact with browser's developers tools.
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
console.log -> it prints normal messages
console.assert -> it is conditional debugger, it checks the condition. If its true it gives nothing and if its false it displays message in console.
The dot . it means to access inside the object.
Loading