Repository navigation
London | 26-Sep-ITP| Frumentius Tesfay | Sprint 2 | Coursework #1541
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
82b0832
227a89f
ec8b86e
e3fd82b
db7e9d1
1cca64e
38f37a7
2c2e03d
92011f6
923135a
a5e6cba
bf8cbcb
68ca43b
588ca6b
491dfc7
caf0ecd
b2957b1
c7309cf
02966a9
5ec9103
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 |
|---|---|---|
|
|
@@ -2,3 +2,6 @@ | |
|
|
||
| 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. Your explanation is right. Run the file though. It still stops with the same error, because line 3 is still
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. Runs now, and the full message is there. Good. |
||
|
|
||
| // Error: TypeError | ||
| // Why: age was declared with const, so it cannot be reassigned. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,6 @@ | |
|
|
||
| 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. The error and the reason are both right, and you have the full message this time. The file still stops when you run it though. What would you move, so that line 4 prints "I was born in 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. That's it. It prints "I was born in Bolton" now. |
||
|
|
||
| // Error: ReferenceError: Cannot access 'cityOfBirth' before initialization | ||
| // Why: cityOfBirth is used before it is declared. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,19 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| const last4Digits = String(cardNumber).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 | ||
|
|
||
|
|
||
| // Prediction: TypeError | ||
| // Why: cardNumber is a number, but slice() is a string method. | ||
|
|
||
| // Actual error: TypeError: cardNumber.slice is not a function | ||
| // The prediction was correct. | ||
|
|
||
| // Fix: convert cardNumber to a string before using slice. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const Hour12ClockTime = "8:53pm"; | ||
| const hour24ClockTime = "20:53"; | ||
| console.log(Hour12ClockTime + " " + hour24ClockTime); | ||
|
|
||
| // Error: SyntaxError: Invalid or unexpected token | ||
| // Why: A JavaScript variable name cannot start with a number. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| const movieLength = 8784; // length of movie in seconds | ||
| const movieLength = 8788; // 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
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. Ignore this one, as I said on the conversation. Changing it is right for f). |
||
|
|
||
| const remainingSeconds = movieLength % 60; | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
@@ -12,14 +12,25 @@ 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) 6 variable declarations | ||
|
|
||
| // b) How many function calls are there? | ||
| // b) 1 function call | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
|
|
||
| // c) % gives the remainder after division. | ||
| // movieLength % 60 finds the remaining seconds after dividing the movie length by 60. | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| // d) totalMinutes is assigned the value 146 after subtracting the remaining seconds | ||
| // from movieLength and dividing the result by 60 | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| // e) It creates the movie's time format | ||
| // Maybe a more descriptive movieTime or movieDuration | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // f) The code works for different whole-number values of movieLength | ||
|
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 says which values it works for. The question also asks whether it works for all values. Try
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, that's the answer.
Author
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. Thank you, Abdi, for your thoughtful comments, guidance, and support as I begin this new chapter of my journey. Your encouragement means a lot to me, and I truly appreciate you taking the time to guide me and others along the way. 🙏 |
||
| // the result changes depending on the movie's length | ||
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.
This is the right answer. The exercise also asks you to break the expression down. What does
Math.random()give you on its own? What does multiplying it by 100 do? And what doesMath.floordo to that result whichMath.roundwould not?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.
Good,
Math.random()andMath.floorare both right now. One piece to add to your notes.Math.random()gives a decimal from 0 up to, but not including, 1. Multiplying by 100 gives 0 up to 99.99.Math.floormakes that 0 to 99. Then+ minimummoves it to 1 to 100.