Skip to content

Commit d93eb5d

Browse files
committed
sprint-1 completed
1 parent 0e2a1e7 commit d93eb5d

File tree

8 files changed

+146
-12
lines changed

8 files changed

+146
-12
lines changed

Sprint-1/1-key-exercises/1-count.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let count = 0;
33
count = count + 1;
44

55
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
6-
// Describe what line 3 is doing, in particular focus on what = is doing
76

8-
//Line 3 is adding 1 to count variable and then saving this new value to count variable
7+
// Describe what line 3 is doing, in particular focus on what = is doing
8+
// Line 3 is adding 1 to count variable and then saving this new value to count variable
99
// = sign is being used to assign the new value of count to the count variable

Sprint-1/1-key-exercises/4-random.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ console.log(num);
1010
// Try logging the value of num and running the program several times to build an idea of what the program is doing
1111

1212
//num in the above code represents integer numbers from 1 to 100
13-
// Math.random() method used in the above code returns floating numbers between 0(inclusive) and 1(exclusive)
13+
// random() method in Math class is used in the above code returns floating numbers between 0(inclusive) and 1(exclusive)
1414
/*and (maximum - minimum + 1) will give use the number that when multiplied by values between
1515
0(inclusive) and 1(exclusive) we will get results from 0 to 99.99999999..... including any decimal values in between
1616
and the Math.floor is used to get rid of the decimal values and return only numbers; so our
17-
values will become 0 to 99 only numbers
18-
and at the end part of the equation we are adding minimum value i.e. 1 which will result in
17+
values will become 0 to 99 only numbers.
18+
And at the end part of the equation we are adding minimum value i.e. 1 which will result in
1919
assigning values from 1 to 100 in num; that's why we are getting only values from 1 to 100 in our num
2020
and every time we print the num in console.log() we can get any values between 1 to 100 depending on the radom value returned
2121
by the Math.random() method.*/

Sprint-1/2-mandatory-errors/2.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
33

4-
console.log(`I was born in ${cityOfBirth}`);
5-
const cityOfBirth = "Bolton";
4+
//console.log(`I was born in ${cityOfBirth}`);
5+
//const cityOfBirth = "Bolton";
66

77
//the above code is not working because you are printing or using the cityOfBirth constant before initializing it
8+
// it can be solved by declaring and initializing the constant before using it as shown below:
9+
const cityOfBirth = "Bolton";
10+
console.log(`I was born in ${cityOfBirth}`);

Sprint-1/3-mandatory-interpret/1-percentage-change.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ const percentageChange = (priceDifference / carPrice) * 100; */
4343
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
4444
/* This code is replacing all the comma characters with an empty character inside the carPrice String and then converting that String to a Number
4545
The purpose of doing this is because in the later part of code we are doing some Math calculations on this number
46-
and, therefore, we can't use String, we need to remove the commas in the String and convert that String into a number
46+
and, therefore, we can't use String, we need to remove the commas in the String and convert that String into a number*/

Sprint-1/3-mandatory-interpret/2-time-format.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@ console.log(result);
1212
// For the piece of code above, read the code and then answer the following questions
1313

1414
// a) How many variable declarations are there in this program?
15+
// Ans: 6
1516

1617
// b) How many function calls are there?
18+
// Ans: 1
1719

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

23+
/* Ans: In this expression the operator % is used which will return the remainder when we divide movieLength by 60
24+
Specifically, in the above code it is used to get the remaining seconds which will be left over after
25+
converting the movieLength i.e given in seconds into minutes. */
26+
2127
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
28+
/* Ans: Here, we are taking out all the remainder or left over seconds from the movieLength seconds
29+
and then dividing that value by 60 to get the length of movie in minutes. */
2230

2331
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24-
32+
/* Ans: result represents the total length of movie in hours, minutes and seconds. The better name
33+
could be "lengthOfMovieInHMS" */
2534
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
35+
// Ans: Yes, this code will work with all number values of movieLength

Sprint-1/3-mandatory-interpret/3-to-pounds.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,47 @@
1+
//initialises a string variable with the value "399p"
12
const penceString = "399p";
23

4+
//creates a substring of penceString to remove the trailing or the last character p value and
5+
//assign the new value to "penceStringWithoutTrailingP"
36
const penceStringWithoutTrailingP = penceString.substring(
47
0,
58
penceString.length - 1
6-
);
9+
); //it will save 399 in penceStringWithoutTrailingP
10+
11+
/* The method padStart is used when we want our string to have at least some length;
12+
in this case if the length of our string is less than 3, we are going to put "0"
13+
in extra spaces
14+
The reason for padding the pence number string to 3 size is because in the next step
15+
we will create a substring by removing the last two values
16+
and that will give us the pounds number value and the remaining characters will be the
17+
pence value. */
18+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); //it will not change our string because 399 already has three characters
719

8-
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
20+
/* Here we are trying to get the pounds value out of the total pence value
21+
Therefore we are creating a substring of paddedPenceNumberString to
22+
create a string that removes the last two numbers from paddedPenceNumberString
23+
which are pence numbers. */
924
const pounds = paddedPenceNumberString.substring(
1025
0,
1126
paddedPenceNumberString.length - 2
1227
);
1328

29+
30+
/* Here, we are doing two things:
31+
1. we are creating a substring of paddedPenceNumberString
32+
to get the pence numbers only by returning the last two numbers.
33+
2. We are using padEnd method to pad our result to two character values
34+
and adding 0 at the end if the length of our substring is less than 2
35+
36+
Note: However, our paddedPenceNumberString length is always going to be at least 3
37+
and the below substring is going to return us the last two characters which is pence value
38+
So, I don't understand the use padEnd and in fact, I tried commenting it and tested the code
39+
with different penceString values and the results are same. */
1440
const pence = paddedPenceNumberString
1541
.substring(paddedPenceNumberString.length - 2)
1642
.padEnd(2, "0");
17-
43+
44+
// in the below code we are printing the value starting with £ symbol of pounds and pence separated by "."
1845
console.log(${pounds}.${pence}`);
1946

2047
// This program takes a string representing a price in pence

Sprint-1/4-stretch-explore/chrome.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ In the Chrome console,
1111
invoke the function `alert` with an input string of `"Hello world!"`;
1212

1313
What effect does calling the `alert` function have?
14+
Ans: It creates an alert message on my tab with the text "Hello world!"
1415

1516
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`.
1617

1718
What effect does calling the `prompt` function have?
19+
Ans: It creates a message box on my tab with the input `"What is your name?"` and there is an input field beneath it for answering this question.
20+
1821
What is the return value of `prompt`?
22+
Mehroz

Sprint-1/4-stretch-explore/objects.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,102 @@ In this activity, we'll explore some additional concepts that you'll encounter i
55
Open the Chrome devtools Console, type in `console.log` and then hit enter
66

77
What output do you get?
8+
ƒ log() { [native code] }
89

910
Now enter just `console` in the Console, what output do you get back?
11+
console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}
12+
assert
13+
:
14+
ƒ assert()
15+
clear
16+
:
17+
ƒ clear()
18+
context
19+
:
20+
ƒ context()
21+
count
22+
:
23+
ƒ count()
24+
countReset
25+
:
26+
ƒ countReset()
27+
createTask
28+
:
29+
ƒ createTask()
30+
debug
31+
:
32+
ƒ debug()
33+
dir
34+
:
35+
ƒ dir()
36+
dirxml
37+
:
38+
ƒ dirxml()
39+
error
40+
:
41+
ƒ error()
42+
group
43+
:
44+
ƒ group()
45+
groupCollapsed
46+
:
47+
ƒ groupCollapsed()
48+
groupEnd
49+
:
50+
ƒ groupEnd()
51+
info
52+
:
53+
ƒ info()
54+
log
55+
:
56+
ƒ log()
57+
memory
58+
:
59+
MemoryInfo {totalJSHeapSize: 11200000, usedJSHeapSize: 10000000, jsHeapSizeLimit: 3760000000}
60+
profile
61+
:
62+
ƒ profile()
63+
profileEnd
64+
:
65+
ƒ profileEnd()
66+
table
67+
:
68+
ƒ table()
69+
time
70+
:
71+
ƒ time()
72+
timeEnd
73+
:
74+
ƒ timeEnd()
75+
timeLog
76+
:
77+
ƒ timeLog()
78+
timeStamp
79+
:
80+
ƒ timeStamp()
81+
trace
82+
:
83+
ƒ trace()
84+
warn
85+
:
86+
ƒ warn()
87+
Symbol(Symbol.toStringTag)
88+
:
89+
"console"
90+
[[Prototype]]
91+
:
92+
Object
93+
1094

1195
Try also entering `typeof console`
96+
It is object
1297

1398
Answer the following questions:
1499

15100
What does `console` store?
101+
console is an object that does not store anything but it is used to call debugging
102+
methods such as log or assert or trace
103+
16104
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
105+
it means that the console object is calling its methods log or assert using the dot "." operator
106+

0 commit comments

Comments
 (0)