-
-
Notifications
You must be signed in to change notification settings - Fork 221
London | 25-ITP-Sep | Imran Mohamed | Sprint 1 | Coursework/sprint 1 #726
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
base: main
Are you sure you want to change the base?
Changes from 15 commits
9f8180d
5641676
678fe4c
92aee19
ceb26e8
ac11085
bf156e2
d60be66
df3c3a8
d7d656b
c172453
cce5a1c
c45239d
11fe4df
8db6c55
8424c04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ 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 = ; | ||
const ext = ; | ||
const dir = filePath.slice(1, lastSlashIndex); | ||
|
||
const ext = base.split(".").pop(); | ||
|
||
// https://www.google.com/search?q=slice+mdn | ||
// https://www.google.com/search?q=slice+mdn |
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? | ||
//We use comments to ignore these lines so the computer doesn't run them |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
// trying to create an age variable and then reassign the value by 1 | ||
|
||
const age = 33; | ||
age = age + 1; | ||
// const age = 33; | ||
// age = age + 1; | ||
|
||
// using let as opposed to const is appropriate here as we intend to reassign the value of age | ||
|
||
let age = 33 | ||
age += 1 | ||
console.log(age) //should log 34; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
// Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
// what's the error ? | ||
|
||
console.log(`I was born in ${cityOfBirth}`); | ||
// console.log(`I was born in ${cityOfBirth}`); | ||
// const cityOfBirth = "Bolton"; | ||
//Uncaught ReferenceError ReferenceError: Cannot access 'cityOfBirth' before initialization is thrown because we are trying to access cityOfBirth before it is declared. | ||
|
||
const cityOfBirth = "Bolton"; | ||
console.log(`I was born in ${cityOfBirth}`); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
const cardNumber = 4533787178994213; | ||
const last4Digits = cardNumber.slice(-4); | ||
// const cardNumber = 4533787178994213; | ||
// const last4Digits = cardNumber.slice(-4); | ||
|
||
// 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 | ||
|
||
//The code will not work because it tries to use a string method on a number | ||
|
||
// 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? | ||
// Consider: Why does it give this error? Is this what I predicted? If not, what's different? | ||
|
||
// error is TypeError: cardNumber.slice is not a function which is what I expected | ||
|
||
|
||
// Then try updating the expression last4Digits is assigned to, in order to get the correct value | ||
// by concatenating an empty string the code works as expected | ||
const cardNumber = "" + 4533787178994213; | ||
|
||
const last4Digits = cardNumber.slice(-4); | ||
console.log(last4Digits); // should log '4213' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
const 12HourClockTime = "20:53"; | ||
const 24hourClockTime = "08:53"; | ||
// const 12HourClockTime = "20:53"; | ||
// const 24hourClockTime = "08:53"; | ||
//throws SyntaxError because variable name cannot start with a number | ||
const twelveHourClockTime = '08:53' | ||
const twentyFourHourClockTime = '20:53' | ||
|
||
console.log(twelveHourClockTime); | ||
console.log(twentyFourHourClockTime); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,13 +13,25 @@ console.log(result); | |
|
||
// a) How many variable declarations are there in this program? | ||
|
||
// There are 6 variable declaration, they are: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result | ||
|
||
// b) How many function calls are there? | ||
|
||
//There is only one function call, the console.log() in line 10 | ||
|
||
// c) Using documentation, explain what the expression movieLength % 60 represents | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
|
||
//movieLength % 60 is the remainder of the division of movieLength by 60 i.e it provides the remaining seconds when movieLength is converted to minutes through the use of the modulus operator % that returns the remainder of a division | ||
|
||
// d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
|
||
// totalMinutes is the total number of full minutes in the movie length , calculated by first removing the remaining seconds then dividing by 60 to convert to minutes | ||
|
||
// e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
||
// result represents the movie length in hours:minutes:seconds format. It would be better to name it formattedMovieLength or movieLengthHMS | ||
|
||
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
|
||
// Yes the code will work for all values of movieLength, because the use of a variable makes it so that the code can be reused for any value of movieLength | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need the string formatting
${}
for this if all you are doing is concatenation?