Skip to content
Closed
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 shows adding 1 to count which was declared and assigned in line 1 which is 0 and assign the result of this operation to count so count will be updated/increment by 1 and equal to 0+1=>1
// = is an assignment operator used to assign value to a variable in this case we are assigning the value of 0+1 or 1 to count. so count will be 1.
8 changes: 5 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,9 @@ 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)}`;
//correction to line 8
console.log(initials);
//string literal interpolation using character at first (0)index.
// 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 @@ -17,7 +17,9 @@ 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 dire = filePath.slice(0, lastSlashIndex);
const ext = filePath.slice(filePath.lastIndexOf("."));
console.log("The Directory is", dire);
console.log("The extension is ", ext);

// https://www.google.com/search?q=slice+mdn
// https://www.google.com/search?q=slice+mdn
26 changes: 25 additions & 1 deletion Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,32 @@ 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

//ANSWER
//the first and second line are variable declaration and each have a value assigned to them.
//next let me breakdown the code in line 4

// Math.floor()
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor
//According to MDN the Math.floor() method always rounds down and returns the largest integer less than or equal to a given number.
//eg. Math.floor(2.6) is 2.

//Math.random()
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
//According to MDN this method gives a random number between 0 and 1 excluding 1. giving unique number every time it is called.
//eg. 0,0.23 , 0.55, 0.99 , 0.01 ...

//now i will break it to solve it
//Math.random() * (maximum - minimum + 1) = Math.random() * (100-1+1) = Math.random()*100
//Math.random()*100 gives random number between 0 to 99 (inclusive).

//Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
//This is the full code of line 4 it is Math.floor(result in line 27)+1
//when we round the result of line 27 to the smallest integer the minimum is 0 and maximum is 99
//but when we add 1 to it the range of our out put will be changed to 1 to 100
//therefore the output will be from 1 to 100.
4 changes: 4 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,7 @@

const age = 33;
age = age + 1;
//Answer : its result will be error since we are trying to change the value of constant variable age.
//the correct code is written below
//let age = 33;
//age += 1;
7 changes: 7 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,10 @@

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";
//Answer
//ReferenceError: Cannot access 'cityOfBirth' before initialization
// the problem is since js execute the code line by line it doesnt get
//the variable when executing line 4 since it is defined on line 5.
//the correct code is written below
//const cityOfBirth ="Bolton";
//console.log(`I was born in ${cityOfBirth}`);
10 changes: 9 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const last4Digits = parseInt(cardNumber.toString().slice(-4));
console.log(last4Digits);

// 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

//Answer
//i think it will give me the digits except the last 4 digits.
//the error is .slice is not a function. this is because it is only used with strings and arrays not numbers.
//so i have to change the format of the number to string by using .toString()
//now it will give the last 4 digits of our string.
//the last 4 digits are changed to number as suggested by mentor using by parseInt()
9 changes: 8 additions & 1 deletion Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const 24hourClockTime = "08:53";
Copy link

Choose a reason for hiding this comment

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

Please fix the error.

There is another error present here. Please carefully compare the variable names to their respective values and see if you notice anything wrong.

Copy link
Author

Choose a reason for hiding this comment

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

done

//Answer
//This is invalid syntax because variable names can not start with numbers
//instead we can say, twelveHourClockTime="20:53";
/*fixed code below
const twelveHourClockTime="08:53 PM";
const twentyFourHourClockTime="20:53";
*/
21 changes: 20 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,30 @@ 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
// 4 , two in line 4 and 2 in line 5.
// Number()
// replaceAll()
// Number()
// 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?
// we have syntax error on line 5 and i have added , in side the bracket to separate "," and "".
// In line 5 it was this => priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));

// c) Identify all the lines that are variable reassignment statements
// line 4 and 5 are reassignments
//carPrice = Number(carPrice.replaceAll(",", "")); AND
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));


// d) Identify all the lines that are variable declarations
// line 1,2,7 and 8 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?
//it is replacing the characters in the string specified in the bracket to make them numbers.
Copy link

Choose a reason for hiding this comment

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

Could you please be just a little bit more specific? Not too in-depth, but be more specific about the details of the function.

Copy link
Author

Choose a reason for hiding this comment

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

done

//example in --- let carPrice = "10,000"; ---carPrice = Number(carPrice.replaceAll(",", ""));
//we replace , and "" from carPrice and store the numeric value of 10000
14 changes: 8 additions & 6 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ const remainingMinutes = totalMinutes % 60;
const totalHours = (totalMinutes - remainingMinutes) / 60;

const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
console.log(result);
console.log(result); //.log() this is a function call

// 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
// b) How many function calls are there?

// 1
// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

// It represent the remainder of movieLength divided by 60 (two operands)
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

// it means movielength without remainder divided by 60 to give how long it take in minutes without the remaining seconds(remainders).
// e) What do you think the variable result represents? Can you think of a better name for this variable?

// it represent the duration of the movie in hr min and sec , "duration" is better variable naming
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
//movie time is always positive but i have checked it using many numbers but when we see it just in correct code perispective since it doesnt work for float numbers and negative numbers (conceptually since their is no negative duration) i can say it lacks some kind of specificity

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
Expand Up @@ -25,3 +25,12 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"
//My Answers
//line 3-6 : here we create a substring(penceStringWithoutTrailingP) from penceString from index 0 to 3. i.e 399
// const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
// this line add a string at the start of penceStringWithoutTrailingP if it is less than 3 char.
//in this case it will add 0 in the begining of the string.
// line 9-12 : this declare pound and pound is equal to substring from the paddedPenceNumberString starting from the first index 0 to its length-2 (leaving the pences).
//line 14-16 :declare pences which are substrings of paddedPenceNumberString which hold the last 2 characters.
//.padEnd makes sure it have 0 to the right if the pence char is less than 2.
//line 18 console logs the pound and pence in correct formatting. eg £2.30
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 @@ -16,3 +16,7 @@ Now try invoking the function `prompt` with a string input of `"What is your nam

What effect does calling the `prompt` function have?
What is the return value of `prompt`?

My answer
alert() shows a popup with a message and terminate when ok is clicked.
prompt() Asks the user for input and returns the entered value this include return value of null if canceled or nothing is given as input.
13 changes: 8 additions & 5 deletions Sprint-1/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?

----it says negative code
Now enter just `console` in the Console, what output do you get back?

----i didnt understand it well but it looks like a list of functions undeer console.
Try also entering `typeof console`

----it is an object
Answer the following questions:

What does `console` store?
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
What does `console` store? --- I think functions.
What does the syntax `console.log` or `console.assert` mean? In particular,
-- console.log means log/display the result of the console and console.assert mean check the values inserted in the console.
what does the `.` mean?
--it is used to use different functions of console