-
-
Notifications
You must be signed in to change notification settings - Fork 336
Glasgow | JAN ITP-2026|Tuan Nguyen | Sprint 1 | Programming-fundamentals #1140
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
ae2a475
20fb215
ba2b449
4a643cc
8d780b8
54de241
62e8714
041e4fc
1f147eb
9fbf280
fcb1b97
1f8489e
fd5b31a
9b4e1ce
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,9 @@ | ||
| let count = 0; | ||
|
|
||
| count = count + 1; | ||
| /* in line three, the variable count is reassign new value by increment it current value by 1. | ||
| */ | ||
| console.log(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,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? | ||
| By comment both the line 1 and 2 out and the system should ignore these 2 line and see them as comment. | ||
| */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| age = age + 1; | ||
| let age = 33; | ||
| age += 1 ; | ||
|
|
||
| console.log(age); | ||
|
|
||
| /*By changing the variable from const to let since const variable value can't be change. I used prefix to increase the value and reassign it right away.*/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const twelveHourClockTime = "20:53"; | ||
| const twentyFourHourClockTime = "08:53"; | ||
| console.log(twelveHourClockTime); | ||
| console.log(twentyFourHourClockTime); | ||
|
|
||
|
Comment on lines
+1
to
+5
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. You changed only part of the code. As such, the code won't run.
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 I have make some change you should be able to check when I make commit to github |
||
| /*For this error I I fix by changing the number 12 and 24 to word variable name because in JS number can't be used to begin writing a variable name */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ let carPrice = "10,000"; | |
| let priceAfterOneYear = "8,543"; | ||
|
|
||
| carPrice = Number(carPrice.replaceAll(",", "")); | ||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); | ||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); | ||
|
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 is fine, but the link below is worth looking into. it's an abstraction over this and will probably serve you better in the long run:
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. @ykamal Thank you for the link. I have read through and see that it indeed more organise then the current method I write in the code. I will try to used in my course work next time. |
||
|
|
||
| const priceDifference = carPrice - priceAfterOneYear; | ||
| const percentageChange = (priceDifference / carPrice) * 100; | ||
|
|
@@ -20,3 +20,30 @@ console.log(`The percentage change is ${percentageChange}`); | |
| // d) Identify all the lines that are variable declarations | ||
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
|
|
||
| /* | ||
| Answer | ||
| a) In this section of the code, we have function calls appear 5 time through out the code. Here is each of them on the line of code that | ||
| they are call: | ||
| - Number(carPrice.replaceAll(",","")); in line 4 is a function calls because the .replaceALL is being executed | ||
| - Number(priceAfterOneYear.replaceAll(",", "")); in line 5 is also a function call because .replaceAll is being executed. | ||
| - Inside the Number() function the .replaceAll in both line 4 and 5 is also a function call because the the parent function is also | ||
| being executed. | ||
| - the console.log is a function calls | ||
| So the total amount of function call in this code is 5 | ||
|
|
||
| b) The main error for the when the running this line of code if for the missing right parameter between the arguments, so fix this | ||
| just add the coma right after the double quote. | ||
|
|
||
| c) There are 2 reassign variable statement at line 4 and line 5. | ||
|
|
||
| d)There are 4 total variable declarations in this code: | ||
| - let carPrice = "10,00"; line 1 | ||
| - let priceAfterOneYear ="8,543"; line 2 | ||
| - const priceDifference = carPrice - priceAfterOneYear; line 7 | ||
| - const percentageChange = (priceDifference / carPrice) * 100; line 8 | ||
|
|
||
| e) The expression Number(carPrice.replaceAll(",","")) are doing 2 main purpose, | ||
| - The first purpose is to remove the coma from the string number "10000" and "8543". | ||
| - Is the changing the string number to number data type. | ||
| */ | ||
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.
Phrases like "a number between X and Y" are not precise enough in a program specification, because they do not clearly state whether the endpoints X and Y are included.
We can also use the concise and precise interval notation to describe a range of values.
[,]=> inclusion(,)=> exclusionFor example,
[1, 10)means, all numbers between 1 and 10, including 1 but excluding 10.Can you practice this and use it to describe the range of numbers that could be produced in each of these sub-expressions?
Math.random()Math.random() * (maximum - minimum + 1)Math.floor(Math.random() * (maximum - minimum + 1))Math.floor(Math.random() * (maximum - minimum + 1)) + minimumThere 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.
Thanks you for the feedback! Here is my explanation about the ranges using interval notation:
Math.random() → produces a float in [0, 1)
Math.random() * (maximum - minimum + 1) → produces a float in [0, maximum - minimum + 1)
Math.floor(Math.random() * (maximum - minimum + 1)) → produces an integer in [0, maximum - minimum]
Math.floor(Math.random() * (maximum - minimum + 1)) + minimum → produces an integer in [minimum, maximum]
This notation makes it clear which endpoints are included or excluded.