-
-
Notifications
You must be signed in to change notification settings - Fork 546
London | 26-ITP-SEP | Bartosz Kawiak | Sprint 2 | Course-work-2 #1542
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 all commits
b285176
ef676e6
b7159b4
0d07b48
50abd73
539375a
7304c3b
a05fb5f
e58f494
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,10 @@ 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(0, lastSlashIndex); | ||
| const ext = filePath.slice(-4); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // https://www.google.com/search?q=slice+mdn | ||
| console.log(dir); | ||
| console.log(ext); | ||
|
|
||
| // https://www.google.com/search?q=slice+mdn | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| This is just an instruction for the first activity - but it is just for human consumption | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your answer on line 4 is right. Have you run the file since you wrote it? Lines 1 and 2 are still read as JavaScript, so node stops here. This exercise wants you to change these two lines, not only describe how it would be done. |
||
| We don't want the computer to run these 2 lines - how can we solve this problem? | ||
| We don't want the computer to run these 2 lines - how can we solve this problem? | ||
|
|
||
| //We have to use the // to comment a single line | ||
| /* or use /* to comment multiple lines */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,5 @@ | |
|
|
||
| const age = 33; | ||
| age = age + 1; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have written that |
||
| /* const means that the variable cannot be reassigned we should use let keyword instead. | ||
| TypeError displayed due to that. */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,8 @@ | |
|
|
||
| console.log(`I was born in ${cityOfBirth}`); | ||
| const cityOfBirth = "Bolton"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good explanation, and the right error. The file still stops when you run it though. What would you move, so that line 4 prints "I was born in Bolton"? |
||
|
|
||
| //The error we see it's a ReferenceError which tells us that we cannot access variable before initialization. | ||
|
|
||
| /*JavaScript reads the code from top to bottom, order is wrong. | ||
| Task cannot be executed as variable cannot be access before being created. */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| const last4Digits = cardNumber.toString().slice(-4); | ||
| console.log(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? | ||
| // Then try updating the expression last4Digits is assigned to, in order to get the correct value | ||
|
|
||
| /*The code would not work because cardNumber variable stores number data type and .slice() method cannot be used on a number, | ||
| if we run the code without changing data type to string we will get TypeError displayed | ||
| I used .toString() method to convert cardNumber variable to a string and then used .slice(-4) to get the last 4 digits. */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right about why this happens. Both names are still here though, so node cannot read the file at all. What would you rename them to? |
||
| const 24hourClockTime = "20:53"; | ||
|
|
||
| //A variable cannot start with a number, SyntaxError is displayed. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| const movieLength = 8784; // length of movie in seconds | ||
| const movieLength = -8784.08; // length of movie in seconds | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was |
||
|
|
||
| const remainingSeconds = movieLength % 60; | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
@@ -23,3 +23,10 @@ console.log(result); | |
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
|
|
||
| //a) There are 6 variable declarations. | ||
| //b)There is 1 function call on line 10 | ||
| //c) movieLength use remainder operator % . movieLength % 60 returns the remaining seconds after dividing the movie length into full minutes. | ||
| //d) expression assigned to totalMinutes calculate movie time in whole minutes. | ||
| //e) This variable represent total movie time in hh/mm/ss format, we could name it totalTime or totalMovieTime. | ||
| //f) Yes, the code works correctly when movieLength is non-negative whole number that represents seconds. | ||
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.
Run this file. It prints
C. Lines 9 and 10 work out the other two characters, but nothing keeps the result, soinitialsonly holds the first one. How can you join all three into one string?