Skip to content

Commit 5cc5f90

Browse files
debug2604debug2604
authored andcommitted
Convert remaining files from CRLF to LF line endings
1 parent 9712617 commit 5cc5f90

11 files changed

Lines changed: 223 additions & 223 deletions

File tree

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
// The diagram below shows the different names for parts of a file path on a Unix operating system
2-
3-
// ┌─────────────────────┬────────────┐
4-
// │ dir │ base │
5-
// ├──────┬ ├──────┬─────┤
6-
// │ root │ │ name │ ext │
7-
// " / home/user/dir / file .txt "
8-
// └──────┴──────────────┴──────┴─────┘
9-
10-
// (All spaces in the "" line should be ignored. They are purely for formatting.)
11-
12-
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
13-
const lastSlashIndex = filePath.lastIndexOf("/");
14-
const base = filePath.slice(lastSlashIndex + 1);
15-
console.log(`The base part of ${filePath} is ${base}`);
16-
17-
// Create a variable to store the dir part of the filePath variable
18-
// Create a variable to store the ext part of the variable
19-
20-
const dir = filePath.slice(0, lastSlashIndex);
21-
const ext = filePath.slice(filePath.lastIndexOf("."));
22-
23-
console.log(dir);
24-
console.log(ext);
25-
26-
// https://www.google.com/search?q=slice+mdn
1+
// The diagram below shows the different names for parts of a file path on a Unix operating system
2+
3+
// ┌─────────────────────┬────────────┐
4+
// │ dir │ base │
5+
// ├──────┬ ├──────┬─────┤
6+
// │ root │ │ name │ ext │
7+
// " / home/user/dir / file .txt "
8+
// └──────┴──────────────┴──────┴─────┘
9+
10+
// (All spaces in the "" line should be ignored. They are purely for formatting.)
11+
12+
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
13+
const lastSlashIndex = filePath.lastIndexOf("/");
14+
const base = filePath.slice(lastSlashIndex + 1);
15+
console.log(`The base part of ${filePath} is ${base}`);
16+
17+
// Create a variable to store the dir part of the filePath variable
18+
// Create a variable to store the ext part of the variable
19+
20+
const dir = filePath.slice(0, lastSlashIndex);
21+
const ext = filePath.slice(filePath.lastIndexOf("."));
22+
23+
console.log(dir);
24+
console.log(ext);
25+
26+
// https://www.google.com/search?q=slice+mdn
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
const minimum = 1;
2-
const maximum = 100;
3-
4-
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
5-
6-
// In this exercise, you will need to work out what num represents?
7-
// Try breaking down the expression and using documentation to explain what it means
8-
// It will help to think about the order in which expressions are evaluated
9-
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10-
11-
// num represents a variable. The expression assign a value to this variable.
12-
// Math.floor () and Math.random () are methods.
13-
// The value inside Math.floor() is its argument. The return value of this argument is expression within the yellow parenthesis.
14-
// The whole expression of variable "num" is that a float generated by method Math.random() is multiplied by return value of the range specified by value between declared variable by key word constant.
15-
// The method Math.floor() then return greatest integer of the value of this product.
16-
// And finally plus the value of minimum variable declared.
17-
18-
//`num` is a random integer between maximum and minimum inclusive.
19-
// The smallest value of 'num' can be 1
20-
21-
console.log(num);
1+
const minimum = 1;
2+
const maximum = 100;
3+
4+
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
5+
6+
// In this exercise, you will need to work out what num represents?
7+
// Try breaking down the expression and using documentation to explain what it means
8+
// It will help to think about the order in which expressions are evaluated
9+
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10+
11+
// num represents a variable. The expression assign a value to this variable.
12+
// Math.floor () and Math.random () are methods.
13+
// The value inside Math.floor() is its argument. The return value of this argument is expression within the yellow parenthesis.
14+
// The whole expression of variable "num" is that a float generated by method Math.random() is multiplied by return value of the range specified by value between declared variable by key word constant.
15+
// The method Math.floor() then return greatest integer of the value of this product.
16+
// And finally plus the value of minimum variable declared.
17+
18+
//`num` is a random integer between maximum and minimum inclusive.
19+
// The smallest value of 'num' can be 1
20+
21+
console.log(num);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +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?
3-
//By adding two slashes at the begining of each line.
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+
//By adding two slashes at the begining of each line.

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// trying to create an age variable and then reassign the value by 1
2-
3-
let age = 33;
4-
age = age + 1;
5-
6-
console.log(age);
7-
8-
//This is a type error. For the expected result of 34, age should not be declared as a constant.
9-
//let should be used instead of const because const is a constant variable and cannot be reassigned.
1+
// trying to create an age variable and then reassign the value by 1
2+
3+
let age = 33;
4+
age = age + 1;
5+
6+
console.log(age);
7+
8+
//This is a type error. For the expected result of 34, age should not be declared as a constant.
9+
//let should be used instead of const because const is a constant variable and cannot be reassigned.

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Currently trying to print the string "I was born in Bolton" but it isn't working...
2-
// what's the error ?
3-
4-
const cityOfBirth = "Bolton";
5-
console.log(`I was born in ${cityOfBirth}`);
6-
7-
//The error is that the variable should be declared as a constant before it is used in the console.log statement.
8-
9-
//This is a ReferenceError.
10-
//In this code, the key word does not need to be constant, it can be let - if this is the case the variable city0fBirth can be reassigned in other lines - instead of constant (which cannot reassign variable).
1+
// Currently trying to print the string "I was born in Bolton" but it isn't working...
2+
// what's the error ?
3+
4+
const cityOfBirth = "Bolton";
5+
console.log(`I was born in ${cityOfBirth}`);
6+
7+
//The error is that the variable should be declared as a constant before it is used in the console.log statement.
8+
9+
//This is a ReferenceError.
10+
//In this code, the key word does not need to be constant, it can be let - if this is the case the variable city0fBirth can be reassigned in other lines - instead of constant (which cannot reassign variable).

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// It was a SyntaxError. An identifier cannot start with a numberical value
2-
3-
const TweleveHourClockTime = "8:53pm";
4-
const TwentyFourhourClockTime = "20:53";
5-
6-
console.log(TweleveHourClockTime);
7-
console.log(TwentyFourhourClockTime);
1+
// It was a SyntaxError. An identifier cannot start with a numberical value
2+
3+
const TweleveHourClockTime = "8:53pm";
4+
const TwentyFourhourClockTime = "20:53";
5+
6+
console.log(TweleveHourClockTime);
7+
console.log(TwentyFourhourClockTime);
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
let carPrice = "10,000";
2-
let priceAfterOneYear = "8,543";
3-
4-
carPrice = Number(carPrice.replaceAll(",", ""));
5-
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
6-
7-
const priceDifference = carPrice - priceAfterOneYear;
8-
const percentageChange = (priceDifference / carPrice) * 100;
9-
10-
console.log(`The percentage change is ${percentageChange}`);
11-
12-
// Read the code and then answer the questions below
13-
14-
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15-
// There are five function calls in this code in lines 4, 5, and 10
16-
// These function calls are Number, replaceAll, and console.log
17-
18-
// 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?
19-
// The error originally came from the replaceAll call for priceAfterOneYear: the two arguments
20-
// (",", "") were missing a comma between them, causing a SyntaxError.
21-
// The fix was adding the missing comma so replaceAll(",", "") has two properly separated arguments.
22-
23-
// c) Identify all the lines that are variable reassignment statements
24-
// Variable reassignment statements on lines 4 and 5.
25-
// Variables carPrice and priceAfterOnYear are originally declared on lines 1 and 2, and reassigned on lines 4 and 5.
26-
27-
// d) Identify all the lines that are variable declarations
28-
// They are lines 1,2,7 and 8.
29-
// On lines 1 and 2, variables carPrice and priceAfterOneYear are declared by let.
30-
// On lines 7 and 8, variables priceDifference and percentageChange are declared by const.
31-
32-
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
33-
// replaceAll(",", "") removes all comma characters from the string, since commas aren't valid in a numeric value.
34-
// Number() then converts the resulting clean string into an actual number, so it can be used in arithmetic.
1+
let carPrice = "10,000";
2+
let priceAfterOneYear = "8,543";
3+
4+
carPrice = Number(carPrice.replaceAll(",", ""));
5+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
6+
7+
const priceDifference = carPrice - priceAfterOneYear;
8+
const percentageChange = (priceDifference / carPrice) * 100;
9+
10+
console.log(`The percentage change is ${percentageChange}`);
11+
12+
// Read the code and then answer the questions below
13+
14+
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15+
// There are five function calls in this code in lines 4, 5, and 10
16+
// These function calls are Number, replaceAll, and console.log
17+
18+
// 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?
19+
// The error originally came from the replaceAll call for priceAfterOneYear: the two arguments
20+
// (",", "") were missing a comma between them, causing a SyntaxError.
21+
// The fix was adding the missing comma so replaceAll(",", "") has two properly separated arguments.
22+
23+
// c) Identify all the lines that are variable reassignment statements
24+
// Variable reassignment statements on lines 4 and 5.
25+
// Variables carPrice and priceAfterOnYear are originally declared on lines 1 and 2, and reassigned on lines 4 and 5.
26+
27+
// d) Identify all the lines that are variable declarations
28+
// They are lines 1,2,7 and 8.
29+
// On lines 1 and 2, variables carPrice and priceAfterOneYear are declared by let.
30+
// On lines 7 and 8, variables priceDifference and percentageChange are declared by const.
31+
32+
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
33+
// replaceAll(",", "") removes all comma characters from the string, since commas aren't valid in a numeric value.
34+
// Number() then converts the resulting clean string into an actual number, so it can be used in arithmetic.
Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
const movieLength = -90.5; // length of movie in seconds
2-
3-
const remainingSeconds = movieLength % 60;
4-
const totalMinutes = (movieLength - remainingSeconds) / 60;
5-
6-
const remainingMinutes = totalMinutes % 60;
7-
const totalHours = (totalMinutes - remainingMinutes) / 60;
8-
9-
const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
10-
console.log(result);
11-
12-
// For the piece of code above, read the code and then answer the following questions
13-
14-
// a) How many variable declarations are there in this program?
15-
// There are six variable declarations in the program, namely :
16-
// movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result
17-
18-
// b) How many function calls are there?
19-
// One function call console.log() in code above.
20-
// The others are declared variables.
21-
22-
// c) Using documentation, explain what the expression movieLength % 60 represents
23-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
24-
// % is remainder operator. This operator returns the remainder after left operand is divided by 60.
25-
26-
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
27-
// The expression means first exclude odd seconds, then convert the movie length in number of complete minutes.
28-
29-
// e) What do you think the variable result represents? Can you think of a better name for this variable?
30-
// The variable result represents length of movie in H:M:S format. A better variable name can be movieLength_HMS
31-
32-
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
33-
// A value of movieLength 3661 will return a result of 1:1:1 where the place value for second does not conforms with leading zero time format.
34-
//The code does not work for all values:
35-
//It does not pad single digits with a leading zero;
36-
//It does not validate to reject negative (e.g.-90 gives "0:-1:-30" ; -90.5 gives "0:-1:-30.5") or decimal input.
1+
const movieLength = -90.5; // length of movie in seconds
2+
3+
const remainingSeconds = movieLength % 60;
4+
const totalMinutes = (movieLength - remainingSeconds) / 60;
5+
6+
const remainingMinutes = totalMinutes % 60;
7+
const totalHours = (totalMinutes - remainingMinutes) / 60;
8+
9+
const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
10+
console.log(result);
11+
12+
// For the piece of code above, read the code and then answer the following questions
13+
14+
// a) How many variable declarations are there in this program?
15+
// There are six variable declarations in the program, namely :
16+
// movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result
17+
18+
// b) How many function calls are there?
19+
// One function call console.log() in code above.
20+
// The others are declared variables.
21+
22+
// c) Using documentation, explain what the expression movieLength % 60 represents
23+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
24+
// % is remainder operator. This operator returns the remainder after left operand is divided by 60.
25+
26+
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
27+
// The expression means first exclude odd seconds, then convert the movie length in number of complete minutes.
28+
29+
// e) What do you think the variable result represents? Can you think of a better name for this variable?
30+
// The variable result represents length of movie in H:M:S format. A better variable name can be movieLength_HMS
31+
32+
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
33+
// A value of movieLength 3661 will return a result of 1:1:1 where the place value for second does not conforms with leading zero time format.
34+
//The code does not work for all values:
35+
//It does not pad single digits with a leading zero;
36+
//It does not validate to reject negative (e.g.-90 gives "0:-1:-30" ; -90.5 gives "0:-1:-30.5") or decimal input.
Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
const penceString = "399p"; // initialises a string variable with the value "399p"
2-
3-
const penceStringWithoutTrailingP = penceString.substring(
4-
0,
5-
penceString.length - 1,
6-
); // use .substring method to extract characters of numerical string, with zero indexing starting from first place of penceString, ending at one digit less than the length of penceString by method .length. Expecting value "399".
7-
8-
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
9-
//declares paddedPenceNumberString variable. To target the length of pence number string in three characters. If not, "0" will be added at the beginning of the string. Expecting value "399".
10-
const pounds = paddedPenceNumberString.substring(
11-
0,
12-
paddedPenceNumberString.length - 2,
13-
); //declares variable for pound. .substring method starting from first character, ending by trimming last two characters by method .length. Expecting value "3"
14-
15-
const pence = paddedPenceNumberString
16-
.substring(paddedPenceNumberString.length - 2)
17-
.padEnd(2, "0"); // declares variable for pence. The argument is paddedPenceNumberString.length - 2,
18-
// which for "399" (length 3) evaluates to 1. So this returns .substring(1), giving the last two
19-
// characters "99" — not a literal -2 argument.
20-
// .padEnd method returns character length of two, if not, "0" will be added at the end of string, for examples "90". Here, expecting "99".
21-
22-
console.log(`£${pounds}.${pence}`); // Prints the return value by Template Literal with '£X.yz" format in console pane.
23-
24-
// This program takes a string representing a price in pence
25-
// The program then builds up a string representing the price in pounds
26-
27-
// You need to do a step-by-step breakdown of each line in this program
28-
// Try and describe the purpose / rationale behind each step
29-
30-
// To begin, we can start with
31-
// 1. const penceString = "399p": initialises a string variable with the value "399p"
32-
33-
// Five Variables declared:
34-
// penceString, penceStringWithoutTrailingP, paddedPenceNumberString,pound, pence
35-
// Three methods used:
36-
//.substring(), .padStart(), .padEnd() .log()
37-
// One property used: .length
1+
const penceString = "399p"; // initialises a string variable with the value "399p"
2+
3+
const penceStringWithoutTrailingP = penceString.substring(
4+
0,
5+
penceString.length - 1,
6+
); // use .substring method to extract characters of numerical string, with zero indexing starting from first place of penceString, ending at one digit less than the length of penceString by method .length. Expecting value "399".
7+
8+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
9+
//declares paddedPenceNumberString variable. To target the length of pence number string in three characters. If not, "0" will be added at the beginning of the string. Expecting value "399".
10+
const pounds = paddedPenceNumberString.substring(
11+
0,
12+
paddedPenceNumberString.length - 2,
13+
); //declares variable for pound. .substring method starting from first character, ending by trimming last two characters by method .length. Expecting value "3"
14+
15+
const pence = paddedPenceNumberString
16+
.substring(paddedPenceNumberString.length - 2)
17+
.padEnd(2, "0"); // declares variable for pence. The argument is paddedPenceNumberString.length - 2,
18+
// which for "399" (length 3) evaluates to 1. So this returns .substring(1), giving the last two
19+
// characters "99" — not a literal -2 argument.
20+
// .padEnd method returns character length of two, if not, "0" will be added at the end of string, for examples "90". Here, expecting "99".
21+
22+
console.log(`£${pounds}.${pence}`); // Prints the return value by Template Literal with '£X.yz" format in console pane.
23+
24+
// This program takes a string representing a price in pence
25+
// The program then builds up a string representing the price in pounds
26+
27+
// You need to do a step-by-step breakdown of each line in this program
28+
// Try and describe the purpose / rationale behind each step
29+
30+
// To begin, we can start with
31+
// 1. const penceString = "399p": initialises a string variable with the value "399p"
32+
33+
// Five Variables declared:
34+
// penceString, penceStringWithoutTrailingP, paddedPenceNumberString,pound, pence
35+
// Three methods used:
36+
//.substring(), .padStart(), .padEnd() .log()
37+
// One property used: .length

0 commit comments

Comments
 (0)