Skip to content

Msatd sprint1 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Sprint-1/errors/0.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
This is just an instruction for the first activity - but it is just for human consumption
We don't want the computer to run these 2 lines - how can we solve this problem?
/*This is just an instruction for the first activity - but it is just for human consumption
We don't want the computer to run these 2 lines - how can we solve this problem?
because these sentences were not nested inside JS's comment syntax.*/
6 changes: 4 additions & 2 deletions Sprint-1/errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// trying to create an age variable and then reassign the value by 1

const age = 33;
/*when const is used to create a variable, it can not be reassigned. So for this practice, i replace
with let to fix this error.*/
let age = 33;
age = age + 1;
console.log(age);
6 changes: 5 additions & 1 deletion Sprint-1/errors/2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?
/*the answer is related to the order that the code was written. the variable declaration followed console.log
instead of preceding it resulting in a reference error. I cut the variable declaration and pasted it above
console.log to resolve the problem.*/

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

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

// The last4Digits variable should store the last 4 digits of cardNumber
// However, the code isn't working
// Before running the code, make and explain a prediction about why the code won't work
// Then run the code and see what error it gives.
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
/* the answer: slice() method does only work on strings and arrays. it does not work on numbers.
so I fixed it by changing the expression in Last4Digits variable. */
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
7 changes: 5 additions & 2 deletions Sprint-1/errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
let HourClockTime = "20:53";
hourClockTime = "08:53";
console.log(hourClockTime); // Output: 08:53
/*Javascript variables can not be started with numbers. I changed const to let so that the variable can
be reassigned to a new value. */
2 changes: 2 additions & 0 deletions Sprint-1/exercises/count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
let count = 0;

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

// Line 1 is a variable declaration, creating the count variable with an initial value of 0
// Describe what line 3 is doing, in particular focus on what = is doing
8 changes: 7 additions & 1 deletion Sprint-1/exercises/decimal.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const num = 56.5678;

console.log(num);
// You should look up Math functions for this exercise https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math

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

// Log your variables to the console to check your answers
const wholeNumberPart = Math.floor(num);
console.log("wHole number is:"+ wholeNumberPart);
const decimalPart = num - wholeNumberPart;
console.log("decimal part is:"+ decimalPart);
const roundedNum = Math.round(num);
console.log("rounded number is:"+ roundedNum);
4 changes: 4 additions & 0 deletions Sprint-1/exercises/initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ let firstName = "Creola";
let middleName = "Katherine";
let lastName = "Johnson";


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

console.log("initials are:" + initials);
16 changes: 14 additions & 2 deletions Sprint-1/exercises/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@
// (All spaces in the "" line should be ignored. They are purely for formatting.)

const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
console.log(filePath);
const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
console.log(lastSlashIndex);
const base = filePath.slice(lastSlashIndex+1);
console.log(base);
console.log(`The base part of ${filePath} is ${base}`);

// Create a variable to store the dir part of the filePath variable
// Create a variable to store the ext part of the variable
const dir = filePath.slice(0,lastSlashIndex+1);
console.log(dir);
// Create a variable to store the ext part of the variables.
const lastDotIndex = filePath.lastIndexOf(".");
const ext = filePath.slice(lastDotIndex+1);
console.log(ext);

//another way to extract ext part of filePath string is:
const ext2 = filePath.split(".").pop();
console.log(ext2);
6 changes: 5 additions & 1 deletion Sprint-1/exercises/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ const minimum = 1;
const maximum = 100;

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

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