-
-
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
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 |
|---|---|---|
|
|
@@ -16,8 +16,17 @@ console.log(`The base part of ${filePath} is ${base}`); | |
|
|
||
| // Create a variable to store the dir part of the filePath variable | ||
| // Create a variable to store the ext part of the variable | ||
|
|
||
| const dir = ; | ||
| const ext = ; | ||
| /* | ||
| const slashIndex = filePath.indexOf("/"); | ||
| const dir =filePath.slice(slashIndex + 0, 45) ; | ||
| const ext =filePath.slice(slashIndex + 49, 53); | ||
|
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. Why keep this code? Best practice is to remove unused code to keep our code clean. And doing so also helps make code review easier. |
||
| console.log(`The dir part of ${filePath} is ${dir}`); | ||
| console.log(`The ext part of ${filePath} is ${ext}`); | ||
| */ | ||
|
|
||
| let dirDirectory = filePath.slice(filePath.indexOf("/"),filePath.lastIndexOf("/")); | ||
| let extDirectory = filePath.slice(filePath.lastIndexOf("/")); | ||
| console.log(`The dir part of the file is ${dirDirectory}.`); | ||
| console.log(`The ext part of the file is ${extDirectory}.`); | ||
|
Comment on lines
+27
to
+30
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. Suppose When you run your code, does your code output the values you expected? |
||
|
|
||
| // https://www.google.com/search?q=slice+mdn | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,16 @@ const maximum = 100; | |
|
|
||
| const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
|
|
||
| console.log(num) | ||
|
|
||
| // In this exercise, you will need to work out what num represents? | ||
| // Try breaking down the expression and using documentation to explain what it means | ||
| // It will help to think about the order in which expressions are evaluated | ||
| // Try logging the value of num and running the program several times to build an idea of what the program is doing | ||
|
|
||
| /*Number data type represents any type of number such as integer, float number(decimal number), infinity number, etc... | ||
| In the code at line 4 the num variable are doing math function that generate a integer between variable minimum and maximum value, | ||
| the floor method behind the Math are is main purpose if to help turn value of a float number and round it up to the nearest integer. | ||
| inside the Math.floor parameter the math random method is choosing a random float number between 0 and 1 and have it multiply with the second expression | ||
| to set the range of possible value range from 0 to under 100. The last plus one to make sure the that number stay above 0(0+1) and to 100(99+1); | ||
| */ | ||
|
Comment on lines
+12
to
+18
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. 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.
For example, Can you practice this and use it to describe the range of numbers that could be produced in each of these sub-expressions?
|
||
| 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($12HourClockTime); | ||
| console.log($24HourClockTime); | ||
|
|
||
|
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. |
||
| /*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. | ||
| */ | ||
Uh oh!
There was an error while loading. Please reload this page.