Skip to content

Commit 91f41d8

Browse files
committed
Sprint one task complete
1 parent 3372770 commit 91f41d8

File tree

12 files changed

+169
-32
lines changed

12 files changed

+169
-32
lines changed

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

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

55
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
66
// Describe what line 3 is doing, in particular focus on what = is doing
7+
// This line (line 3), is updating the value of the count variable. The = operator is an
8+
// assignment operator which assigns the value on the right (count + 1) to the variable on the left (count).

Sprint-1/1-key-exercises/2-initials.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ let lastName = "Johnson";
44

55
// Declare a variable called initials that stores the first character of each string.
66
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
7+
let initials = firstName[0] + middleName[0] + lastName[0];
78

8-
let initials = ``;
9-
10-
// https://www.google.com/search?q=get+first+character+of+string+mdn
11-
9+
// https://www.google.com/search?q=get+first+character+of+string+mdn

Sprint-1/1-key-exercises/3-paths.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ console.log(`The base part of ${filePath} is ${base}`);
1717
// Create a variable to store the dir part of the filePath variable
1818
// Create a variable to store the ext part of the variable
1919

20-
const dir = ;
21-
const ext = ;
20+
const dir = filePath.slice(0, lastSlashIndex);
21+
const ext = base.slice(base.lastIndexOf("."));
2222

2323
// https://www.google.com/search?q=slice+mdn

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,16 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
77
// Try breaking down the expression and using documentation to explain what it means
88
// It will help to think about the order in which expressions are evaluated
99
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10+
11+
// Math.random returns a random number between 0 (inclusive) and 1 (exclusive).
12+
// const minimum = 1; const maximum = 100; +1 so, 100 - 1 + 1 = 100
13+
// Math.random() * 100 means the decimal number will be multiplied by 100, so the range of possible values is from 0 to 99.9999...
14+
// Math.floor rounds the number down to the nearest whole number, so the possible values are from 0 to 99.
15+
// Eg. 12.9 becomes 12, 0.3 becomes 0, 99.9 becomes 99.
16+
// Brackets(), Multiply*, Function(Math.floor), Addition+
17+
// 1) Pick a random number between 0 and 1, eg. 0.5
18+
// 2) Multiply that number by 100, eg. 0.5 * 100 = 50
19+
// 3) Round that number down to the nearest whole number, eg. Math.floor(50) = 50
20+
// 4) Add 1 to that number, eg. 50 + 1 = 51
21+
22+
// num represents a random whole number between 1 and 100.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
This is just an instruction for the first activity - but it is just for human consumption
2-
We don't want the computer to run these 2 lines - how can we solve this problem?
1+
// This is just an instruction for the first activity - but it is just for human consumption
2+
// We don't want the computer to run these 2 lines - how can we solve this problem?
3+
// The forward slash is used to indicate a comment in JavaScript, so the computer will ignore these lines when running the program.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
// trying to create an age variable and then reassign the value by 1
22

3-
const age = 33;
3+
let age = 33;
44
age = age + 1;
5+
console.log(age);
6+
7+
// The code above will output 34, because we are reassigning the value of age
8+
// to be the current value of age plus 1. So, 33 + 1 = 34.
9+
// The error in the code is that it was trying to reassign a value to a variable
10+
// that was declared with let. This is not allowed in JavaScript.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
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}`);
54
const cityOfBirth = "Bolton";
5+
console.log(`I was born in ${cityOfBirth}`);
6+
7+
// The error happens because cityOfBirth is used before it is defined. JavaScript runs
8+
// code from top to bottom, so the variable must be declared first.

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
1+
// Currently trying to print the string "I was born in Bolton" but it isn't working...
2+
// what's the error ?
33

4-
// The last4Digits variable should store the last 4 digits of cardNumber
5-
// However, the code isn't working
6-
// Before running the code, make and explain a prediction about why the code won't work
7-
// Then run the code and see what error it gives.
8-
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
9-
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
4+
const cityOfBirth = "Bolton";
5+
console.log(`I was born in ${cityOfBirth}`);
6+
7+
// The error happens because cityOfBirth is used before it is defined. JavaScript
8+
// runs code from top to bottom, so the variable must be declared first.

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
1+
// const 12HourClockTime = "20:53";
2+
// const 24hourClockTime = "08:53";
3+
4+
// Variables cannot start with a number.
5+
// When JavaScript tries to run the code, it throws a SyntaxError.
6+
// To fix the error we can rename the variable to start with a letter, a
7+
// underescore_ or a dollar sign $ instead of a number.
8+
9+
const twelveHourClockTime = "8:53";
10+
const twentyFourHourClockTime = "08:53";
11+
12+
// I changed the time to match the 12 and 24 hr clock format.

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

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let carPrice = "10,000";
22
let priceAfterOneYear = "8,543";
33

44
carPrice = Number(carPrice.replaceAll(",", ""));
5-
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
5+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",",""));
66

77
const priceDifference = carPrice - priceAfterOneYear;
88
const percentageChange = (priceDifference / carPrice) * 100;
@@ -11,12 +11,49 @@ console.log(`The percentage change is ${percentageChange}`);
1111

1212
// Read the code and then answer the questions below
1313

14-
// a) How many function calls are there in this file? Write down all the lines where a function call is made
14+
// a) How many function calls are there in this file? Write down all the
15+
// lines where a function call is made
16+
17+
// There are 5 function calls in this file. They are on lines 1, 2, 4, and 5.
18+
// The functions being called are replaceAll() and Number().
19+
// Line 4: replaceAll and Number (2)
20+
// Line 5: replaceAll and Number (2)
21+
// Line 10: console.log (1)
22+
23+
24+
25+
// b) Run the code and identify the line where the error is coming from - why is
26+
// this error occurring? How can you fix this problem?
27+
28+
// The error is occuring on line 5. It is occuring because there is a missing
29+
// comma between the replaceAll "".
30+
// We can fix this by adding a comma between the two empty strings in the replaceAll
31+
// function on line 5, like this: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
32+
1533

16-
// 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?
1734

1835
// c) Identify all the lines that are variable reassignment statements
1936

37+
// carPrice = Number(carPrice.replaceAll(",", ""));
38+
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
39+
40+
41+
2042
// d) Identify all the lines that are variable declarations
2143

22-
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
44+
// Lines 1,2,7 and 8.
45+
// let carPrice = "10,000";
46+
// let priceAfterOneYear = "8,543";
47+
// const priceDifference = carPrice - priceAfterOneYear;
48+
// const percentageChange = (priceDifference / carPrice) * 100;
49+
50+
51+
52+
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing -
53+
// what is the purpose of this expression?
54+
55+
// carPrice.replaceAll(",", "") - Replaces all commas "," in the string with
56+
// nothing "". e.g "10,000" becomes "10000".
57+
// Number() - Converts the resulting string "10000" into the number 10000.
58+
// The purpose of this is to take a string with commas (like "10,000") and turn
59+
// it into a number (10000) that we can do math with.

0 commit comments

Comments
 (0)