Skip to content

Commit d2bfb65

Browse files
committed
last of errors fixed
1 parent bc1dbce commit d2bfb65

14 files changed

Lines changed: 45 additions & 62 deletions

File tree

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ count = count + 1;
66

77
// Describe what line 3 is doing, in particular focus on what = is doing
88

9-
10-
119
//Line 1 is a declaration and Line 3 is a statement that changes the value of the variable 'count' by adding 1 to its current value.
12-
//The variable is changing from 0 to 1 after line 3 is executed after we used 'let' to declare the variable 'count' and then we used the = operator to assign the new value.
10+
//The variable is changing from 0 to 1 after line 3 is executed after we used 'let' to declare the variable 'count' and then we used the = operator to assign the new value.

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ const lastName = "Johnson";
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.
77

8-
//const initials = ``;
8+
//const initials = ``;
99

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

12+
const initials =
13+
firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0);
1214

13-
const initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0);
14-
15-
console.log (initials);
16-
17-
18-
15+
console.log(initials);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ const dir = filePath.slice(0, lastSlashIndex);
2121

2222
const ext = base.slice(base.lastIndexOf("."));
2323

24-
2524
console.log(dir);
2625
console.log(ext);
2726

28-
29-
30-
// https://www.google.com/search?q=slice+mdn
27+
// https://www.google.com/search?q=slice+mdn

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,24 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
55

66
console.log(num);
77

8-
98
// In this exercise, you will need to work out what num represents?
109
// Try breaking down the expression and using documentation to explain what it means
1110
// It will help to think about the order in which expressions are evaluated
1211
// Try logging the value of num and running the program several times to build an idea of what the program is doing
1312

1413
//Num represents a random whole number between the value of 'minimum' (1) and 'maximum' (100)
15-
//By creating a constant variable called 'num' and assigning it the value of the expression, we can generate a random number within the mentioned range.
14+
//By creating a constant variable called 'num' and assigning it the value of the expression, we can generate a random number within the mentioned range.
1615

1716
//When running the program we have to understand how the expression works:
1817

1918
//we have to work out the parentheses first, maximum - minimum + 1, which is equal to 100 - 1 + 1 = 100.
2019
//so: Math.floor(Math.random() *100) + 1
2120
// Math.floor is used 1 time and it happens before + minimum. Math.floor is used because when used Math.random() it produces a decimal number between 0 and 1.
2221
//The code needs a whole number because we are trying to get a number between 1 and 100, this is where Math.floor comes () comes in and removes the decimal part.
23-
//JavaScript works out the expression inside Math.floor () first before + minimum.
24-
//Math.random() produces a pseudo-random decimal number that is greater than or equal to 0 but less than 1.
22+
//JavaScript works out the expression inside Math.floor () first before + minimum.
23+
//Math.random() produces a pseudo-random decimal number that is greater than or equal to 0 but less than 1.
2524

26-
//Next, we need to multiply the result from Math.random() by 100. This may give us the result of a decimal between 0 and 100.
27-
//Next step is to use Math.floor() wich then rounds down the decimal number to the nearest whole integer. This then means that the result will be a whole number between 0 and 99.
25+
//Next, we need to multiply the result from Math.random() by 100. This may give us the result of a decimal between 0 and 100.
26+
//Next step is to use Math.floor() wich then rounds down the decimal number to the nearest whole integer. This then means that the result will be a whole number between 0 and 99.
2827
//But we want 1-100, so we add 1 to the result of Math.floor() this then changes the range to be inclusive of 1 and 100.
2928
//Therefore, the final result of num will be a random whole number between 1 and 100, inclusive.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//This is just an instruction for the first activity - but it is just for human consumption
2-
//We don't
2+
//We don't
33

44
// want the computer to run these 2 lines - how can we solve this problem?
55

66
//We can add 2 forward slashes , by typing two forward slashes ( // ) at the beginning of the line, we can turn both lines into a comment. This then means that the computer will completely ignore that line and not run it.
7-

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
// trying to create an age variable and then reassign the value by 1
2-
let age= 33;
2+
let age = 33;
33
age = age + 1;
44

5-
console.log (age);
5+
console.log(age);
66

7-
8-
9-
//const means that the variable age is a constant and cannot be reassigned. When we try to reassign the value of age by adding 1 to it, we get an error.
10-
//This is because we cannot change the value of a constant variable once we have created it.
7+
//const means that the variable age is a constant and cannot be reassigned. When we try to reassign the value of age by adding 1 to it, we get an error.
8+
//This is because we cannot change the value of a constant variable once we have created it.
9+
//// The error is a TypeError: Assignment to constant variable.
1110

1211
//If we want to change the value of age, we need to use let instead of consts when declaring the variable. this then allows us to reassign the value of age by adding 1 to it.
13-
14-
15-

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

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

4-
//error
4+
// The error is a ReferenceError: Cannot access 'cityOfBirth' before initialization
55

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

99
//The reason there is an error is because we are using the wrong order, we are telling Javascript to print the value of cityOfBirth before creating a variable.
1010
//So we need to create the variable first, this is because Javascript runs code from top to bottom, so a variable that is declared with const needs to be declared before using it.
1111

12-
13-
1412
//right way
1513

1614
const cityOfBirth = "Bolton";
17-
console.log (`I was born in ${cityOfBirth}`);
15+
console.log(`I was born in ${cityOfBirth}`);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ const last4Digits = String(cardNumber).slice(-4);
88
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
99
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
1010

11-
1211
console.log(last4Digits);
1312

1413
//I think that Javascript will give an error because .slice() is normally used with strings, and cardNumber is currently a number.
15-
//const cardNumber = 4533787178994213; does not have any quotation marks, so Javascript will treat it as a number.
14+
//const cardNumber = 4533787178994213; does not have any quotation marks, so Javascript will treat it as a number.
1615

17-
//When run with console.log(last4Digits); we get --> TypeError : cardNumber.slice is not a function
16+
//When run with console.log(last4Digits); we get --> TypeError : cardNumber.slice is not a function
1817

19-
//.slice is a method used with strings and we need to make cardNumber into a string by adding quotation marks.I
18+
//.slice is a method used with strings and we need to make cardNumber into a string by adding String before cardNumber.
2019

21-
//we can change the expression by making it intoa string by doing --> const last4Digits = String(cardnumber).slice(-4);
20+
//we can change the expression by making it into a string by doing --> const last4Digits = String(cardnumber).slice(-4);
2221
//String(cardNumber) changes the number into a string and .slice(-4) takes the last 4 characters and stores it in last4Digits.
23-
//const cardNumber = 4533787178994213 to const cardNumber = "4533787178994213";
24-
//Now cardNumber is a string, then we can re run the code with console.log(last4Digits); to get the correct code.
22+
//const cardNumber = 4533787178994213 , const last4Digits = cardNumber.slice(-4); change that to --> const last4Digits = String(cardNumber).slice(-4);
23+
//I added String before cardNumber to change the original cardNumber into a string, so we can use the slice() method.
24+
//Now cardNumber is a string, then we can re run the code with console.log(last4Digits); to get the correct code.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ const hour24ClockTime = "20:53";
66

77
console.log(hour24ClockTime);
88

9-
10-
11-
129
//Variable names cannot start with a number as Javascript doesn't allow it, it can contain a number inside the variable but not at the beginning.
10+
// The error is a SyntaxError: Invalid or unexpected token

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

Lines changed: 4 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;
@@ -12,7 +12,7 @@ console.log(`The percentage change is ${percentageChange}`);
1212
// Read the code and then answer the questions below
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15-
//>
15+
//>
1616
// There are 5 function calls, two function calls on line 4 = Number(...) and replaceAll(...) two more on line 5 = Number(...) and replaceAll(...) and finally on line 10 = console.log(...)
1717

1818
// 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?
@@ -23,8 +23,8 @@ console.log(`The percentage change is ${percentageChange}`);
2323
//>carPrice = Number(carPrice.replaceAll(",", "")); and priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
2424

2525
// d) Identify all the lines that are variable declarations
26-
//>There are 4 variable declarations- 1) let carPrice = "10,000"; 2) let priceAfterOneYear = "8,543";
26+
//>There are 4 variable declarations- 1) let carPrice = "10,000"; 2) let priceAfterOneYear = "8,543";
2727
//3) const priceDifference = carPrice-priceAfterOneYear; 4) const percentageChange = (priceDifferenc/carPrice)* 100;
2828

2929
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
30-
//>Number(carPrice.replaceAll(",", "")); is a string and the expression removes the comma from "10,000" and converts "10000" from a string into the number 10000.
30+
//>Number(carPrice.replaceAll(",", "")); is a string and the expression removes the comma from "10,000" and converts "10000" from a string into the number 10000.

0 commit comments

Comments
 (0)