-
-
Notifications
You must be signed in to change notification settings - Fork 336
London | 26-ITP-January | Khaliun Baatarkhuu | Sprint 1 | Coursework. #1030
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
7f1a52d
672d4d6
deb7eef
eddb7aa
d50f377
4d9ad54
8e9765f
ced4d8c
eaf8513
fca8c46
33eb3b2
ec4e15c
48d4945
5d0742b
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,6 +1,7 @@ | ||
| let count = 0; | ||
|
|
||
| count = count + 1; | ||
| count = count + 1; | ||
| // line 3 is assigning the variable "count" a new value of "count +1", then storing it back into "count". | ||
|
|
||
| // Line 1 is a variable declaration, creating the count variable with an initial value of 0 | ||
| // Describe what line 3 is doing, in particular focus on what = is doing | ||
| 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? | ||
|
|
||
| //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? | ||
|
|
||
| // I have erased the above two lines, to prevent the computer from running them. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| let age = 33; | ||
| age = age + 1; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // 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"; | ||
|
|
||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| //const 12HourClockTime = "20:53"; | ||
| //const 24hourClockTime = "08:53"; | ||
|
|
||
| const twentyFourHourClockTime = "20:53"; | ||
| const twelveHourClockTime = "08:53"; | ||
|
|
||
| //variable names in js cannot start with numbers |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,27 @@ | ||
| const penceString = "399p"; | ||
|
|
||
| // 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
| const penceStringWithoutTrailingP = penceString.substring( | ||
| 0, | ||
| penceString.length - 1 | ||
| ); | ||
|
|
||
| //2. Removes the trailing "p" from the pencestring, leaving 399 as the new value. | ||
| const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
| //3. This line ensures there are three characters, at least, by adding "0" to the start if necessary. | ||
| const pounds = paddedPenceNumberString.substring( | ||
| 0, | ||
| paddedPenceNumberString.length - 2 | ||
| ); | ||
|
|
||
| //4. We are extracting the pounds now, ie the first character. | ||
| const pence = paddedPenceNumberString | ||
| .substring(paddedPenceNumberString.length - 2) | ||
| .padEnd(2, "0"); | ||
|
|
||
| //4. Here, we are extracting the last two digits, ie pence. Padend insures there are two digits and adds a "0" to compensate, if necessary. | ||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| console.log(`£${pounds}.${pence}`); | ||
| //5. Here it should show the final result of £3.99 | ||
|
|
||
|
|
||
| // This program takes a string representing a price in pence | ||
| // The program then builds up a string representing the price in pounds | ||
|
|
||
| // You need to do a step-by-step breakdown of each line in this program | ||
| // Try and describe the purpose / rationale behind each step | ||
|
|
||
| // To begin, we can start with | ||
| // 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,16 @@ invoke the function `alert` with an input string of `"Hello world!"`; | |
|
|
||
| What effect does calling the `alert` function have? | ||
|
|
||
| 1. This function displays a pop-up box with Hello world written on it, with on OK button. | ||
|
|
||
| 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? | ||
|
|
||
| 2. It displays a pop-up box with What's your name written on it and an empty dialog box inside, awaiting my input. | ||
| Also, there are two options of OK and Cancel. | ||
|
|
||
| What is the return value of `prompt`? | ||
|
|
||
| 3. If I enter my name undefined appears, same if i press the cancel button. Fixed this by adding myName at the end. | ||
| Now the value when i enter my name shows "my name", if i press cancel it shows "null". | ||
|
Comment on lines
+26
to
+27
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. What you observed were the output produced by When a value is output on the console, it is converted to a string first. As such, just by looking at the output, we could not tell the actual type of the value being returned by the function. For examples, in both of the following actions,
Can you look up the
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. Window.prompt() returns a string containing the text entered by the user, or null.
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. @cjyuan Good morning, Thank you for your hard work reviewing everything and your feedback. I think, i have completed and understood all the points you have raised. Could you have another look, please? Khaliun |
||
Uh oh!
There was an error while loading. Please reload this page.