-
-
Notifications
You must be signed in to change notification settings - Fork 382
London | 26-ITP-May | Damilola Odumosu | Sprint 1 | Coursework #1364
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
1f88977
f2ed2f5
302efee
63ea100
7f35b33
e6d78a0
4ffd303
78253f1
df2d214
d8e5852
bae8454
20eeeea
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 |
|---|---|---|
|
|
@@ -12,12 +12,15 @@ | |
| const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; | ||
| const lastSlashIndex = filePath.lastIndexOf("/"); | ||
| const base = filePath.slice(lastSlashIndex + 1); | ||
|
|
||
| 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 , 44); | ||
| console.log(dir) | ||
| const ext = filePath.slice(lastSlashIndex + 5 ); | ||
| console.log(ext) | ||
|
Comment on lines
+21
to
+24
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. Could you explore an approach that could work for any valid file path? For examples, |
||
|
|
||
| // 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 | ||
| 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?*/ | ||
|
|
||
| //Answer | ||
| //We will comment it out. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| /* we cannot reassign a variable that was declared using the const keyword so we will change it to the let keyword | ||
| which allows us to reassign variables*/ | ||
|
|
||
| let age = 33; | ||
| age = age + 1; | ||
| console.log(age) |
| 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 ? | ||
|
|
||
| console.log(`I was born in ${cityOfBirth}`); | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
|
|
||
|
|
||
| /* The variable is declared after it's been used and when we run the code we get this > ReferenceError: Cannot access | ||
| 'cityOfBirth' before initialization */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,22 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| //const cardNumber = 4533787178994213; | ||
| //const last4Digits = cardNumber.slice(-4); | ||
|
|
||
|
|
||
| // to fix the code, we'll convert the number to a string because .slice does not work on number data type | ||
| let cardNumber = 4533787178994213; | ||
| cardNumber = cardNumber.toString() | ||
| let 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 | ||
| // 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 | ||
|
|
||
| //Answer | ||
| // We are not logging to the console | ||
| // The slice method should be a positive number to represent the index position. | ||
|
|
||
| console.log(last4Digits) | ||
| //TypeError: cardNumber.slice is not a function |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const _12HourClockTime = "8:53pm"; | ||
| const $24hourClockTime = "20:53"; | ||
|
Comment on lines
+1
to
+2
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. Identifiers that begin with Could you explore names that start with alphabets instead? Feel free to ask AI for suggestion. |
||
|
|
||
| //when starting a variable name with a number we have to precede with either of _ or $ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ let carPrice = "10,000"; | |
| let priceAfterOneYear = "8,543"; | ||
|
|
||
| carPrice = Number(carPrice.replaceAll(",", "")); | ||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); | ||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); | ||
|
|
||
| const priceDifference = carPrice - priceAfterOneYear; | ||
| const percentageChange = (priceDifference / carPrice) * 100; | ||
|
|
@@ -12,11 +12,18 @@ console.log(`The percentage change is ${percentageChange}`); | |
| // Read the code and then answer the questions below | ||
|
|
||
| // a) How many function calls are there in this file? Write down all the lines where a function call is made | ||
| // There are 3 function calls. line 4 Number() and .replaceAll() | ||
| // line 12 console,log() | ||
|
|
||
| // 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? | ||
| //A syntaxError is occurring on line 5, we are missing a "," and a closing ")" | ||
|
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. We can more precisely describe "A comma is missing between What is the programming term that belongs in the blank? Note: The original code does not have a missing closing ")". |
||
|
|
||
| // c) Identify all the lines that are variable reassignment statements | ||
| // line 4 and 5 | ||
|
|
||
| // d) Identify all the lines that are variable declarations | ||
|
|
||
| // line 1, 2, 7, 8 | ||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
| /* We are removing the comma, the replaceAll method takes in two arguements, 1 for what to replace and 2 for what to | ||
| replace by, and in this case we are replaceing the comma with an empty string. we wrap the carPrice variable which is a string | ||
| with the Number() function to convert it into a number*/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| const movieLength = 8784; // length of movie in seconds | ||
| // const movieLength = 8784; // length of movie in seconds | ||
| const movieLength = 879094; // length of movie in seconds | ||
|
|
||
| const remainingSeconds = movieLength % 60; | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
@@ -12,14 +13,24 @@ console.log(result); | |
| // For the piece of code above, read the code and then answer the following questions | ||
|
|
||
| // a) How many variable declarations are there in this program? | ||
| // 6 | ||
|
|
||
| // b) How many function calls are there? | ||
| // 1 | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
| // % is the modulos operator, movieLength % 60 gives us the remainder, essentially we divide 60 by movieLenght and return the remainder | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| /* we are subtracting remainingSeconds from movieLength, remainingSeconds is a variable that holds the result from totalMinutes % 60, | ||
| the expression in brackets will evaluate first and then the result divided by 60. | ||
| */ | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| //runTime | ||
|
Comment on lines
-24
to
+31
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.
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| /* I have experimented with different values by changing the movieLength variable, and they all work, it works because we have | ||
| didn't hardcode our expressions and used variables. | ||
| */ | ||
|
|
||
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.
Operation like
count = count + 1is very common in programming, and there is a programming term describing such operation.Could you find out what one-word programming term describes the operation on line 3?