-
-
Notifications
You must be signed in to change notification settings - Fork 386
London | ITP- Jan- 2026 | Ping Wang | Sprint 1 | coursework #928
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
Changes from 36 commits
cbac6c9
ec6019a
09f6da9
78c873b
887fcdd
3cd21a7
024cbc0
b2e0a5d
fbf096a
700ffe3
589052b
0d5917b
e06ea00
ff6aac5
f48e433
eb00ebe
9082058
cd05719
fa07668
2d7234f
62528e6
1270352
de9068f
42da013
b0a3afc
d7dbde9
718a5a4
ba7388c
9b20e8f
7106030
0d13cdf
ce86675
6645f44
52a9d62
1177a65
a9977bb
4cb4496
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,4 @@ | ||
| 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? | ||
|
|
||
| //In JavaScript, we put // in front of sentence which is only for human to read. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| // 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,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}`); | ||
| //my answer: | ||
| // we should put variable declaration first then print out as JS languages rules, can not write the other way around | ||
|
|
||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,21 @@ | ||
| 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 | ||
|
|
||
| //my answer: | ||
| //slice() only works for string or Array,cardNumber is number so i predict that the computer will give TypeError. When i | ||
| //run this Code, my prediction is right. In order to fix it, first cast to string first: | ||
|
|
||
| const cardNumber=4533787178994213; | ||
|
|
||
| //then convert to string | ||
| const last4Digits = cardNumber.toString().slice(-4); | ||
| console.log(last4Digits); | ||
|
|
||
| // or i can put quotes on cardNumber which will be string | ||
| const cardNumber1 ="4533787178994213" | ||
| const last4Digits1 = cardNumber1.slice(-4); | ||
| console.log(last4Digits1) | ||
|
Comment on lines
+12
to
+21
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 initiative shown by executing the task in more than one way. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,8 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const 24hourClockTime = "08:53"; | ||
|
|
||
| // cost 12HourClockTime = "20.53" is wrong code because 20 is more than 12 and variable name can not start with digital in JavaScript. | ||
| // The right coe should be: | ||
|
|
||
| const TwelveHourClockTime = "08:53 pm" | ||
| const TwentyFourHourClockTime = "20:53" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,4 +15,27 @@ What effect does calling the `alert` function have? | |
| Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. | ||
|
|
||
| What effect does calling the `prompt` function have? | ||
| What is the return value of `prompt`? | ||
| What is the return value of `prompt` | ||
|
|
||
| >alert("Hello World!") | ||
| the pop up box:chrome://new-tab-page says Hello world! i press ok button, return undefined.the pop up box pauses JS execution until press ok | ||
| <.undefined | ||
| >myName = prompt("What is your name") | ||
| <.'ping' | ||
| Warning: Don’t paste code into the DevTools Console that you don’t understand or haven’t reviewed yourself. This could allow attackers to steal your identity or take control of your computer. Please type ‘allow pasting’ below and press Enter to allow pasting. | ||
| allow pasting | ||
| The value returned from prompt() is stored in the variable myName. | ||
| The pop-up box pauses JavaScript execution until the user responds by either: | ||
|
|
||
| typing a value and pressing OK → returns the input string, or | ||
|
|
||
| pressing Cancel → returns null. | ||
| This return value can then be used in the program, for example: | ||
|
|
||
| console.log("Your name is:", myName); | ||
|
|
||
|
|
||
| In some Chrome setups, I may need to grant permissions to allow pop-ups for prompt to work properly in DevTools. | ||
|
Comment on lines
+27
to
+38
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. Much improved answer. However, make sure you understand what the functions to be run in the devtools properly as shown in the task. And yes, make sure your permissions are in place to have a stress-free time using devtools |
||
|
|
||
|
|
||
|
|
||
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.
Yes, your code runs with the desired output, but it is best practice to try to follow the provided template for you in the task. A variable was initialised as a template literal, but your solution provides another way to do it.