-
-
Notifications
You must be signed in to change notification settings - Fork 546
London | 26-ITP-Sep | Ebrahim Moqbel | Sprint 2 | Coursework #1467
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
4032809
50fcc71
749a886
0173fea
47925f5
dc50152
46954bb
312c629
fc23e35
afa549f
b8014c0
ae10a10
39c9dc7
08a3ec6
7b1645e
5bc8fbe
04451b1
ae0d9d5
356c45f
6ae9f42
f3c67ac
c4bb72c
1dd1e64
cd39a5a
8f31dc9
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 |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| 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? |
| 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; | ||
| let age = 33; | ||
| age = age + 1; | ||
|
|
||
| /* | ||
| The error thrown was a TypeError indicating assignment to constant variable and this happen when | ||
| we declare a variable with const and try to give it a new value | ||
|
|
||
| */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // 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 error is that cityOfBirth variable declared after the logging command |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| // 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 | ||
| // 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 | ||
|
|
||
| // I predicted the last four digits bit it has to be a string in order to use the method slice and that explain why it wasn't working | ||
| const last4Digits = cardNumber.toString().slice(-4); | ||
| console.log(last4Digits); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const twelveHourClockTime = "8:53pm"; | ||
|
Ebrahim-Moqbel marked this conversation as resolved.
|
||
| const twentyFourHourClockTime = "20:53"; | ||
| // The old version of the variables return a SyntaxError pointing that there is Invalid or unexpected token | ||
| // For naming the variables we need to use the naming convention which involved not leading the variable name with a number | ||
|
|
||
| console.log(twelveClockTime); | ||
|
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. Run |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,26 @@ 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? | ||
| //A--> There are 6 variable declarations | ||
|
|
||
| // b) How many function calls are there? | ||
| //A--> There are 1 function call in line 10 which is ===> console.log(result); | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // c) Usings documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
| //A--> % is a modulo operator that return the remainder which is the leftover of a division of two numbers | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
|
|
||
| /* movieLength subtract the left over seconds from the total seconds(movieLength) to get a number that is divisible by 60 | ||
| when dividing by 60 would convert the remaining seconds into whole minutes which ensures there is no decimal in totalMinutes | ||
| */ | ||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| //A--> results present length of movie formatted as Hours:Minutes:Seconds and a better name could be fromatedMovieDuration | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| /*whole positive value: for the 8784 seconds the formatted duration would be fine 2:26:24 and the code would be working as expected | ||
| under 60 seconds: 59 seconds would assign the hours and minutes both as 0s resulting 0:0:59 instead of the normal formatted way 00:00:59 but still correct | ||
|
Ebrahim-Moqbel marked this conversation as resolved.
|
||
| zero value: the formatted duration would also be correct 0:0:0 even though it is an unusual value it still show that it can handle it | ||
| Negative value: for the -8784 seconds would give us an output of -2:-26:-29 which is not a valid format and doesn't make any sense | ||
|
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 changed the positive case on line 33 to 8784, good. This line still carries the seconds from the old number. What does the program print for -8784?
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 one is still open. Run the program with -8784 and compare the seconds with what line 35 says. |
||
| the logic breaks where we need to give the user a message to enter a valid number | ||
| */ | ||
Uh oh!
There was an error while loading. Please reload this page.