-
-
Notifications
You must be signed in to change notification settings - Fork 239
London | 25-ITP-SEP | Mariia Serhiienko| Sprint 1 | Module-Structuring-and-Testing Data Coursework #829
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?
London | 25-ITP-SEP | Mariia Serhiienko| Sprint 1 | Module-Structuring-and-Testing Data Coursework #829
Changes from all commits
b975ffa
8f8263e
1473a63
492c04f
3eb8410
ee3a0b1
94fb26c
b64a8f6
e9b50c2
bbf4e20
85635a5
4f7798d
a7f84c3
157a8ce
8a0ebbb
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 |
|---|---|---|
|
|
@@ -7,3 +7,22 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | |
| // 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 | ||
|
|
||
| console.log(`Random number between ${minimum} and ${maximum}: ${num}`); | ||
|
|
||
| console.log( | ||
| "Random number between 0 and 1 after evaluating Math.random() is: ", | ||
|
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 use the concise and precise interval notation to describe a range of values.
For example, we could describe 'x' where Can you use this notation to describe the return value of |
||
| Math.random() | ||
| ); | ||
| console.log( | ||
| "Math.random() * (maximum - minimum + 1) scales the range from 1 to 100 (100 isn't included) for the random number: ", | ||
| Math.random() * (maximum - minimum + 1) | ||
| ); | ||
| console.log( | ||
| "Math.floor(Math.random() * (maximum - minimum + 1)) rounds down the random number: ", | ||
| Math.floor(Math.random() * (maximum - minimum + 1)) | ||
| ); | ||
| console.log( | ||
| "(Math.floor(Math.random() * (maximum - minimum + 1)) + minimum) shifts the range to 1–100 (100 is included): ", | ||
| Math.floor(Math.random() * (maximum - minimum + 1)) + minimum | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| 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? |
| 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,5 @@ | ||
| // 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}`); | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| const last4Digits = cardNumber.toString().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 | ||
| console.log(`The last 4 digits of the card number are: ${last4Digits}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const _12HourClockTime = "20:53"; | ||
| const hour24ClockTime = "08:53"; | ||
|
Comment on lines
+1
to
+2
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 use different naming styles? |
||
| 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(",", "")); | ||
|
|
||
| const priceDifference = carPrice - priceAfterOneYear; | ||
| const percentageChange = (priceDifference / carPrice) * 100; | ||
|
|
@@ -12,11 +12,23 @@ console.log(`The percentage change is ${percentageChange}`); | |
| // Read the code and then answer the questions below | ||
|
|
||
| // a) How many function calls are there in this file? Write down all the lines where a function call is made | ||
| // Line 4: Number(), carPrice.replaceAll(",", "") - 2 function calls | ||
| // Line 5: Number(), priceAfterOneYear.replaceAll(",", "") - 2 function calls | ||
| // Line 10: console.log() - 1 function call | ||
| // In total: 5 function calls | ||
|
|
||
| // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? | ||
| // Its line 5 - missed comma in replaceAll method. Fixed now - added comma after the first parameter. | ||
|
|
||
| // c) Identify all the lines that are variable reassignment statements | ||
| // Line 4: carPrice = Number(carPrice.replaceAll(",", "")); | ||
| // Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); | ||
|
|
||
| // d) Identify all the lines that are variable declarations | ||
| // Line 1: let carPrice = "10,000"; | ||
| // Line 2: let priceAfterOneYear = "8,543"; | ||
| // Line 7: const priceDifference = carPrice - priceAfterOneYear; | ||
| // Line 8: const percentageChange = (priceDifference / carPrice) * 100; | ||
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
| // This expression transforms data type from String to Number and removes all commas from the String value of carPrice, so "10,000" becomes "10000". | ||
|
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. Between the two operations, "convert a string to a number" and "remove all commas", which of them happened first? To avoid confusion, it is best to describe them in the order they are carried out in the program. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // 1.Write a function that will calculate the area of a rectangle. The function should take two parameters: length and width. It should return the area of the rectangle. | ||
|
|
||
| function calculateArea(length, width) { | ||
| const area = length * width; | ||
| return area; | ||
| } | ||
|
|
||
| console.log(calculateArea(3, 4)); // Output: 12 | ||
|
|
||
| // 2.Write a function that will capitalize the first letter in a given string. | ||
|
|
||
| function capitalizeFirstLetter(name) { | ||
| const result = name[0].toUpperCase() + name.slice(1); | ||
| return result; | ||
| } | ||
|
|
||
| console.log(capitalizeFirstLetter("mario")); // Output: "Mario" |
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.
Operation like
count = count + 1is very common in programming, and there is a programming term describing such operation.Can you find out what one-word programming term describes the operation on line 3?