-
-
Notifications
You must be signed in to change notification settings - Fork 546
Cape Town | sep-2026-itp | Matthaus Bause | Sprint 2| Complete Sprint 2 courswork #1528
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
ced2c8b
dfe221f
20df3e3
5817f0b
857487a
66bd2de
8bc3b93
adf2ba2
1979160
b6c78a5
cf2d074
3c9fa22
04a9d41
daa9c1f
c1fc3d4
4e8e014
0300b47
1543377
bb8c532
f873d15
eb8a31f
15d2158
a9d224e
379adb3
f3df854
aff145b
877bec1
569b188
80746e7
56ac4cd
79b5ec2
68c38be
3df39c3
2f89dbe
544f99d
eadc040
598a6ec
13b9006
15a0c9b
9fe7705
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,7 @@ | ||
| 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 don't want the computer to run these 2 lines - how can we solve this problem? | ||
|
|
||
| //By commenting it out | ||
|
|
||
| //This is just an instruction for the first activity - but it is just for human consumption | ||
|
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. Did you manage to run this file after your change? what is the output?
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. I didn't run it as I believe there was no need to run, considering it being commented lines so that devs can have a look at what the comments are referring to when reading through the code |
||
| //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,6 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| let age = 33; | ||
| age = age + 1; | ||
|
|
||
| console.log(age); |
| 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 ? | ||
| // Answer: because javascript runs from top to bottom, by declaring the const after running console.log the function throws an error because the decleration is done ater console.log | ||
|
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. Did you manage to note the exact error that happened here in the original file?
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. Terminals throws a Reference error |
||
|
|
||
| console.log(`I was born in ${cityOfBirth}`); | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const cardNumber = "4533787178994213"; | ||
|
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 have another look at which part of this the exercise asks you to update?
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. Was I suppose to convert the number into a string? |
||
| 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 .slice() can't be called using numeric values only string values | ||
| // Then run the code and see what error it gives. | ||
| // This is just an instruction for the first activity - but it is just for human consumption | ||
| //TypeError: cardNumber.slice is not a function | ||
| // 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 | ||
| console.log(last4Digits) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const clockTime12Hour = "8:53pm"; | ||
| const clockTime24Hour = "20:53"; | ||
|
|
||
| console.log(clockTime12Hour); | ||
| console.log(clockTime24Hour); | ||
|
|
||
| // variable names can't be declared when starting with numbers, only letters |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,20 +6,26 @@ const totalMinutes = (movieLength - remainingSeconds) / 60; | |
| const remainingMinutes = totalMinutes % 60; | ||
| const totalHours = (totalMinutes - remainingMinutes) / 60; | ||
|
|
||
| const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; | ||
| console.log(result); | ||
| const timeRemainingHHMMSS = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; | ||
| console.log(timeRemainingHHMMSS); | ||
|
|
||
| // 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? | ||
| // i) There are 5 variable declerations. Lines 1, 3, 4, 6, 7 and 9 | ||
|
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 point out which variables did you identify?
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. line 12: filePath |
||
|
|
||
| // b) How many function calls are there? | ||
| // ii) There is only one function call. 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 | ||
| // iii) the % is a remainder operator telling us how many remaining seconds are left in the variable decleration in line 1 | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| // iv) line 4 is taking the movieLength 8784 - remainingSeconds 24 which leaves us with a whole value of 146 for the totalMinutes variable decleration. | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| // v) It represents the total time remaining in HH:MM:SS format, perhaps changing variable decleration to timeRemainingHHMMSS would be more descriptive in what we are trying to achieve? | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // vi) this code won't work for negative number values and non-numeric values, I noticed that single-digit values don't follow the HHMMSS it shows HMSS depending on the value input used such as movieLength = 52. | ||
|
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. Nice catch on the padding issue with single-digit values! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,18 @@ In this activity, we'll explore some additional concepts that you'll encounter i | |
| Open the Chrome devtools Console, type in `console.log` and then hit enter | ||
|
|
||
| What output do you get? | ||
| Answer: function log() { (native code) } | ||
|
|
||
| Now enter just `console` in the Console, what output do you get back? | ||
| Answer: Output is 'console {debug: function, error: function, info: function, log: function, warn: function, ...} with a drop down list of all functions' | ||
|
|
||
| Try also entering `typeof console` | ||
| Answer: output is 'object' | ||
|
|
||
| Answer the following questions: | ||
|
|
||
| What does `console` store? | ||
| Answer: this stores all the functions that the console has. | ||
|
|
||
| What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? | ||
| Answer: 'console' is an object and 'log/assert' is properties of log. the `.` is going to look-up which property is stored in the object | ||
|
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. Properties of log or of something else?
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. Oh shoot! |
||
Uh oh!
There was an error while loading. Please reload this page.