Skip to content

Commit 45f409b

Browse files
committed
#reverted sprint 1commit
1 parent d6f14a8 commit 45f409b

File tree

14 files changed

+12
-128
lines changed

14 files changed

+12
-128
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ 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 we are taking the current value of count (which is 0) and adding 1 to it, and store the new value back into count" so now count is 1.the = is an assignment operator that Assigns values to variables so it takes the value on the right side (count + 1) and assigns it to the variable on the left side (count).

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ let 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-
let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`;
8+
let initials = ``;
99

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

12-
console.log(initials); //that should print "CKJ"
13-
//so the code is going to check the first character of each variable that means “the character at position 0

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +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 = filePath.slice(0, lastSlashIndex);// the slice is a method that cuts out part of a string and returns it as a new string. we use it here to get the dir part of the filePath
21-
const ext = base.slice(base.lastIndexOf("."));//the ext is any thing after the last dot
22-
//const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
23-
//const dir = "/Users/mitch/cyf/Module-JS1/week-1/interpret";
24-
25-
console.log(`The dir part of ${filePath} is ${dir}`);
26-
console.log(`The ext part of ${filePath} is ${ext}`);
20+
const dir = ;
21+
const ext = ;
2722

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

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

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,8 @@ const minimum = 1;
22
const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
5-
console.log(num);
65

76
// In this exercise, you will need to work out what num represents?
87
// Try breaking down the expression and using documentation to explain what it means
98
// It will help to think about the order in which expressions are evaluated
109
// Try logging the value of num and running the program several times to build an idea of what the program is doing
11-
12-
//num is a random number between minimum and maximum (inclusive)
13-
/*Math.random()
14-
15-
This gives you a random decimal number between 0 (inclusive) and 1 (exclusive) — meaning it can be 0, but never exactly 1.
16-
17-
Example outputs:
18-
0.23
19-
20-
/*(maximum - minimum + 1)
21-
22-
This calculates how many whole numbers are in the range, including both ends.
23-
24-
Example:
25-
100 - 1 + 1 = 100
26-
27-
So, there are 100 possible integers from 1 to 100.
28-
29-
/*Math.random() * (maximum - minimum + 1)
30-
31-
This scales the random decimal to the desired range size.
32-
33-
Example if Math.random() gave 0.57:
34-
0.57 * 100 = 57
35-
/*Math.floor(...)
36-
The Math.floor() method in JavaScript is used to round a number down to the nearest integer, regardless of whether the number is positive or negative or has a decimal part.
37-
Example:
38-
Math.floor(57.8) → 57
39-
40-
/*+ minimum
41-
42-
Finally, we shift the range up so it starts at 1 instead of 0.
43-
0–99 becomes 1–100*/
44-
45-
//The order for evaluation is:
46-
/*maximum - minimum + 1
47-
48-
Math.random() * (that result)
49-
50-
Math.floor(...)
51-
52-
+ minimum*/
53-
54-
//I run the code several times and got different numbers one was 60 the other one was 88

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +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?
3-
4-
5-
//if we have any instructions or explanations in our code without the computer executing them,we can use comments
6-
//comments In javascript are created by using (//) for single line comments
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: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,3 @@
22

33
const age = 33;
44
age = age + 1;
5-
// This will give an error because we only use const for Fixed values so we can change const to let
6-
let age = 33;
7-
age = age + 1;
8-
console.log(age); // that should print 34

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

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

4-
const cityOfBirth = "Bolton";
54
console.log(`I was born in ${cityOfBirth}`);
6-
//we have to declare the variable cityOfBirth with const or let before using it in the console.log statement
5+
const cityOfBirth = "Bolton";

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
const cardNumber = 4533787178994213;
22
const last4Digits = cardNumber.slice(-4);
3-
console.log(last4Digits);
3+
44
// The last4Digits variable should store the last 4 digits of cardNumber
55
// However, the code isn't working
66
// Before running the code, make and explain a prediction about why the code won't work
7-
//the slice method is used for strings not numbers.
87
// Then run the code and see what error it gives.
9-
//Uncaught TypeError: cardNumber.slice is not a function
108
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
11-
//javascript can not slice a number
129
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
13-
//I have added the console.log to see the output.
14-
//there is another way to get the last 4 digits by using slice method is to convert the number to a string first by using toString() method
15-
const last4Digits = cardNumber.toString().slice(-4); //it wil print "4213"
16-
//If you want it to be a number, you can convert it back:
17-
const last4Digits = Number(cardNumber.toString().slice(-4));
18-
Now last4Digits will be 4213 as a number.

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
11
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
3-
4-
//because variables names cannot start with a number
5-
//I have changed the variable names to start with a letter
6-
const twelveHourClockTime = "08:53 PM";
7-
const twentyFourHourClockTime = "20:53";
8-
console.log(twelveHourClockTime);
9-
console.log(twentyFourHourClockTime);
10-
// that should print "08:53 PM" and "20:53"
2+
const 24hourClockTime = "08:53";

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

Lines changed: 2 additions & 17 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,26 +12,11 @@ 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-
//after running the code I found 5 function calls
16-
//line 1: replaceAll
17-
//line 2: replaceAll
18-
//line 4: Number
19-
//line 5: Number
20-
//line 8: console.log
15+
2116
// 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?
22-
// after running the code i found an error in line 5 missing a comma in the replaceAll method to fix it I have added the comma
2317

2418
// c) Identify all the lines that are variable reassignment statements
25-
carPrice = Number(carPrice.replaceAll(",", ""));
26-
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
27-
2819

2920
// d) Identify all the lines that are variable declarations
30-
let carPrice = "10,000";
31-
let priceAfterOneYear = "8,543";
32-
const priceDifference = carPrice - priceAfterOneYear;
33-
const percentageChange = (priceDifference / carPrice) * 100;
3421

3522
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
36-
// Fist the car price is a string so we can't do any calculation on it yet
37-
//so first we remove all the comma by using replaceAll method then we convert it to a number by using Number method

0 commit comments

Comments
 (0)