Skip to content

Commit db4dc5d

Browse files
new coursework sprint 1
1 parent b31a586 commit db4dc5d

15 files changed

Lines changed: 54 additions & 63 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ 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+
// In Line 3, count is a variable, and the = is an assignment operator that stores the result of the operation(Addition)
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
let firstName = "Creola";
2-
let middleName = "Katherine";
3-
let lastName = "Johnson";
4-
51
// Declare a variable called initials that stores the first character of each string.
62
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
73

84
let initials = ``;
5+
let initials = firstName.charAt(0)+ middleName.charAt(0) + lastName.charAt(0);
6+
console.log(initials);
97

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

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ console.log(`The base part of ${filePath} is ${base}`);
2020
const dir = ;
2121
const ext = ;
2222

23+
const dir =filePath.slice(0, filePath.lastIndexOf("/")+1);
24+
const ext =filePath.slice(filePath.indexOf(".")+1);
25+
console.log(dir)
26+
console.log(ext)
2327
// https://www.google.com/search?q=slice+mdn
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
const minimum = 1;
21
const maximum = 100;
32

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

66
// In this exercise, you will need to work out what num represents?
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+
//The math.Floor method rounds a number to the nearest integer, so using bodmas,
11+
//the expressions are evaluated, the minimum which equals 1 is added to 1 then subtracted from maximum(100), after which it is multiplied by
12+
//a random number between 0-1 exclusive and then rounded down to the nearest integer after which the minimum is added. The values produced ranges from 0-100

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
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?

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

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

33
const age = 33;
4-
age = age + 1;
4+
let age = 33;
5+
age = age + 1;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
// what's the error ?
33

44
console.log(`I was born in ${cityOfBirth}`);
5+
// what's the error ? You cannot access a variable before initialization.
56
const cityOfBirth = "Bolton";
7+
console.log(`I was born in ${cityOfBirth}`);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const cardNumber = 4533787178994213;
2+
const cardNumber = '4533787178994213';
23
const last4Digits = cardNumber.slice(-4);
34

45
// 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
6+
const last4Digits = cardNumber.slice(-4);
77
// Then run the code and see what error it gives.
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
10+
//It didn't work because the method only works for strings so to make it work the card number should be saved as a string.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
const 12HourClockTime = "8:53pm";
2-
const 24hourClockTime = "20:53";
1+
const TwelveHourClockTime = "8:53pm";
2+
const TwentyFourHourClockTime = "20:53";

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,27 @@ let priceAfterOneYear = "8,543";
33

44
carPrice = Number(carPrice.replaceAll(",", ""));
55
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
6+
carPrice = Number(carPrice.replaceAll(",",""));
7+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",",""));
68

79
const priceDifference = carPrice - priceAfterOneYear;
810
const percentageChange = (priceDifference / carPrice) * 100;
9-
1011
console.log(`The percentage change is ${percentageChange}`);
11-
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+
//The function call are made five times
16+
//line 4, 5, 10
17+
1518

1619
// 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?
1720

21+
// Line 5, it was missing a comma between the characters that are to be replaced so to fix the problem, include a comma
22+
1823
// c) Identify all the lines that are variable reassignment statements
24+
//Lines 7 & 8
1925

2026
// d) Identify all the lines that are variable declarations
21-
27+
//Lines 1 & 2
2228
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
29+
//This expression replaces every instance of "," with "".

0 commit comments

Comments
 (0)