-
-
Notifications
You must be signed in to change notification settings - Fork 546
Manchester | 26-ITP-Sep | Gustarv Nchitu | Sprint 2 | Coursework/sprint 2 #1593
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
d778f5c
b04b242
8a27562
0ffcbc8
8191573
3ff94aa
1abe61a
43b8618
8ca06db
f56c69c
cec8b9b
f86c338
bccc1dd
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,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? | ||
| 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,12 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| //const age = 33; | ||
| //age = age + 1; | ||
|
|
||
| // We use let because the value of age needs to change. | ||
|
|
||
|
|
||
| let age = 33; | ||
|
|
||
| age = age + 1; | ||
| console.log(age); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,12 @@ | ||
| // 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}`); | ||
| //console.log(`I was born in ${cityOfBirth}`); | ||
| //const cityOfBirth = "Bolton"; | ||
|
|
||
| // Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
| // what's the error ? | ||
|
|
||
| const cityOfBirth = "Bolton"; | ||
|
|
||
| console.log(`I was born in ${cityOfBirth}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,15 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| //const cardNumber = 4533787178994213; | ||
| //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 predict the code will give an error because cardNumber is a number, and slice() works on strings. | ||
| //const last4Digits = String(cardNumber).slice(-4); | ||
| const cardNumber = 4533787178994213; | ||
|
|
||
| const last4Digits = String(cardNumber).slice(-4); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| //const 24hourClockTime = "20:53"; | ||
| // I predict the code will give an error because a variable name cannot start with a number. | ||
| const twelveHourClockTime = "8:53pm"; | ||
|
Comment on lines
+2
to
+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. Your understanding is correct. There were two variable declarations in the original code though. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,3 +23,11 @@ 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. It is on line 10: console.log(result); | ||
| // c) The % operator gives the remainder after dividing movieLength by 60. | ||
| // c) The % operator gives the remainder after dividing movieLength by 60. 60 represents the number of seconds in one minute. | ||
| // d) It subtracts the remaining seconds from the movie length and then divides by 60 to convert the remaining seconds into total minutes. | ||
| // e) The variable result represents the movie duration in hours, minutes and seconds. A better name would be movieDuration. | ||
|
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 name Could you suggest a more descriptive name? |
||
| // f) The code works for different positive values of movieLength because it converts seconds into hours, minutes and seconds. It expects movieLength to be a number representing seconds. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,6 @@ Now try invoking the function `prompt` with a string input of `"What is your nam | |
|
|
||
| What effect does calling the `prompt` function have? | ||
| What is the return value of `prompt`? | ||
| Calling the alert function displays a pop-up message to the user. | ||
|
|
||
| Calling the prompt function asks the user for information. The return value of prompt is the information the user entered. | ||
|
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. When a program uses prompt() to ask the user for input, how can it tell whether the user clicked "OK" or "Cancel"? |
||
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.
I just noticed you missed this exercise.
Could you give a precise description what each of these expressions does, and the range of the numbers it may produce?
Math.random()Math.random() * (maximum - minimum + 1)Math.floor(Math.random() * (maximum - minimum + 1))Math.floor(Math.random() * (maximum - minimum + 1)) + minimumNote: To describe a range of numbers, we could use the concise and precise interval notation:
[,]=> inclusion(,)=> exclusionFor example,$x$ is a number in $[1, 10)$ means: