Skip to content

Commit 7a52923

Browse files
authored
Merge pull request #1 from SueMsOl/MSATD-sprint1
Msatd sprint1
2 parents 9e19f9c + 0ef45a8 commit 7a52923

File tree

10 files changed

+54
-13
lines changed

10 files changed

+54
-13
lines changed

Sprint-1/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+
because these sentences were not nested inside JS's comment syntax.*/

Sprint-1/errors/1.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// trying to create an age variable and then reassign the value by 1
2-
3-
const age = 33;
2+
/*when const is used to create a variable, it can not be reassigned. So for this practice, i replace
3+
with let to fix this error.*/
4+
let age = 33;
45
age = age + 1;
6+
console.log(age);

Sprint-1/errors/2.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
3+
/*the answer is related to the order that the code was written. the variable declaration followed console.log
4+
instead of preceding it resulting in a reference error. I cut the variable declaration and pasted it above
5+
console.log to resolve the problem.*/
36

4-
console.log(`I was born in ${cityOfBirth}`);
57
const cityOfBirth = "Bolton";
8+
console.log(`I was born in ${cityOfBirth}`);
9+

Sprint-1/errors/3.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
1+
const cardNumber = 4533787178994213; // const cardNumber = `${4533787178994213}` also fixes the error by changing data type to string.
2+
const last4Digits = cardNumber.toString().slice(-4);
3+
console.log(`The last 4 digits of the card number are: ${last4Digits}`);
34

45
// The last4Digits variable should store the last 4 digits of cardNumber
56
// However, the code isn't working
67
// Before running the code, make and explain a prediction about why the code won't work
78
// Then run the code and see what error it gives.
89
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
10+
/* the answer: slice() method does only work on strings and arrays. it does not work on numbers.
11+
so I fixed it by changing the expression in Last4Digits variable. */
912
// Then try updating the expression last4Digits is assigned to, in order to get the correct value

Sprint-1/errors/4.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
1+
let HourClockTime = "20:53";
2+
hourClockTime = "08:53";
3+
console.log(hourClockTime); // Output: 08:53
4+
/*Javascript variables can not be started with numbers. I changed const to let so that the variable can
5+
be reassigned to a new value. */

Sprint-1/exercises/count.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
let count = 0;
22

33
count = count + 1;
4+
/*line 3 reassigns the value that was passed onto count variable by using an arithmetic operator to add
5+
1 to count variable's value.*/
46

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

Sprint-1/exercises/decimal.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
const num = 56.5678;
2-
2+
console.log(num);
33
// You should look up Math functions for this exercise https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
44

55
// Create a variable called wholeNumberPart and assign to it an expression that evaluates to 56 ( the whole number part of num )
66
// Create a variable called decimalPart and assign to it an expression that evaluates to 0.5678 ( the decimal part of num )
77
// Create a variable called roundedNum and assign to it an expression that evaluates to 57 ( num rounded to the nearest whole number )
88

99
// Log your variables to the console to check your answers
10+
const wholeNumberPart = Math.floor(num);
11+
console.log("wHole number is:"+ wholeNumberPart);
12+
const decimalPart = num - wholeNumberPart;
13+
console.log("decimal part is:"+ decimalPart);
14+
const roundedNum = Math.round(num);
15+
console.log("rounded number is:"+ roundedNum);

Sprint-1/exercises/initials.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@ let firstName = "Creola";
22
let middleName = "Katherine";
33
let lastName = "Johnson";
44

5+
56
// Declare a variable called initials that stores the first character of each string.
67
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
8+
let initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0);
9+
10+
console.log("initials are:" + initials);

Sprint-1/exercises/paths.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,21 @@
1010
// (All spaces in the "" line should be ignored. They are purely for formatting.)
1111

1212
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
13+
console.log(filePath);
1314
const lastSlashIndex = filePath.lastIndexOf("/");
14-
const base = filePath.slice(lastSlashIndex + 1);
15+
console.log(lastSlashIndex);
16+
const base = filePath.slice(lastSlashIndex+1);
17+
console.log(base);
1518
console.log(`The base part of ${filePath} is ${base}`);
1619

1720
// Create a variable to store the dir part of the filePath variable
18-
// Create a variable to store the ext part of the variable
21+
const dir = filePath.slice(0,lastSlashIndex+1);
22+
console.log(dir);
23+
// Create a variable to store the ext part of the variables.
24+
const lastDotIndex = filePath.lastIndexOf(".");
25+
const ext = filePath.slice(lastDotIndex+1);
26+
console.log(ext);
27+
28+
//another way to extract ext part of filePath string is:
29+
const ext2 = filePath.split(".").pop();
30+
console.log(ext2);

Sprint-1/exercises/random.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ const minimum = 1;
22
const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
5+
/*due to rules of precedence, parenthesis executes first. Inside parenthesis, subtraction executes first,
6+
then addition executes.*/
7+
console.log("random number:" + num);
8+
/*num keeps changing because Math.random() function outputs a different random value between 0 and 1 every time it runs. */
59

6-
// In this exercise, you will need to work out what num represents?
10+
// In this exercise, you will need to work out what num represents? answer: a numerical value
711
// Try breaking down the expression and using documentation to explain what it means
812
// It will help to think about the order in which expressions are evaluated
913
// Try logging the value of num and running the program several times to build an idea of what the program is doing

0 commit comments

Comments
 (0)