-
-
Notifications
You must be signed in to change notification settings - Fork 240
Manchester | 25-ITP-Sep | Hani Sadah| Sprint 1 | Coursework/sprint 1 #810
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 4 commits
af8a542
e4c2e57
b21591e
4102ecb
8f90b4f
1da375f
beda7c4
e7f48d3
a661310
f4e13bc
b6b4ffc
2478f22
8beb07d
f070a00
ad0f006
e082897
85bcc9b
491f9b8
c5a8edb
b0547d6
9b194a5
75b0d32
6b1aed0
883efa2
4ca75b9
e4ba658
c57d664
9bf4964
d868527
9b9dc8e
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 |
|---|---|---|
|
|
@@ -8,17 +8,14 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | |
| // 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 | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| //num represents the results of equations at the right side of operator = | ||
|
|
||
| //step-1---> Math.random() generates a random decimal. | ||
| //step-2---> (maximum - minimum + 1) evaluates to 100. | ||
| //step-3---> Math.random() is multiplied by (maximum - minimum + 1) which is 100, resulting in a random decimal between 0 and 100. | ||
|
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, we can describe a number, Can you use this notation to describe the return value of |
||
| //step-4---> the result of Step-3 is round by the method Math.floor. | ||
| //step-5---> minimum is added to the result of step-4. | ||
| //Therefore, num represents random numbers generated between minimum 1 and maximum 100, as we run the code several times | ||
| //generates new numbers. | ||
|
|
||
| console.log(num); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,13 @@ | ||
| // Predict and explain first... | ||
| // =============> I predict that we will not need to write let in line 8 as str is already declared | ||
| // as an argument within the function captialise. | ||
| // =============> write your prediction here | ||
|
|
||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
|
|
||
| // function capitalise (str) { | ||
| // let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| // return str; | ||
| // } | ||
|
|
||
| // capitalise ('hello'); | ||
| //==============> A syntaxError occurred as 'str' is being cleared. | ||
|
|
||
|
|
||
| function capitalise(str) { | ||
| str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
| console.log (capitalise ('hello')); | ||
|
|
||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your new code here |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,20 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> I believe that the function convertToPercentage is not mentioned in the console.log statement. | ||
| // Declaring the const decimalNumber is unnecessary as it is already declared as a parameter within the function convertToPercentage. | ||
| // =============> write your prediction here | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| // function convertToPercentage(decimalNumber) { | ||
| // const decimalNumber = 0.5; | ||
| // const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| // return percentage; | ||
| //} | ||
|
|
||
| // console.log(decimalNumber); | ||
|
|
||
| // =============> A syntaxError occurred saying decimalNumber is already declared. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
| function convertToPercentage() { | ||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(convertToPercentage()); | ||
| console.log(decimalNumber); | ||
|
|
||
| // =============> write your explanation here | ||
|
|
||
| // the new code runs without error and outputs "50%" | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,14 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> In line 6, instead of console.log printing the result of multiply(10, 32), return a*b would be better | ||
| //because the console.log would only print a*b. | ||
| // =============> write your prediction here | ||
|
|
||
| //function multiply(a, b) { | ||
| //console.log(a * b); | ||
| //} | ||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| //console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> After running the code, we got 'the result of multiplying 10 and 32 is undefined' | ||
| // as the multiply parameters weren't considered as parameters inside the function multiply. | ||
| // =============> write your explanation here | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function multiply(a, b) { | ||
| return a * b; | ||
| } | ||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| // Predict and explain first... | ||
| // =============> SyntaxError will occur due to putting a semicolon after return. | ||
| // =============> write your prediction here | ||
|
|
||
| function sum(a, b) { | ||
| return a + b; | ||
| return; | ||
| a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> unlike the expectation that the code runs without error as 'the sum of 10 and 32 is undefined'. | ||
| // =============> write your explanation here | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // we needed just to remove the semicolon after return statement and to bring up the a+b expression side by side with return. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,24 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Predict the output of the following code: | ||
| // =============> The code will return 3 as a string first, but after calling the getLastDigit function, | ||
| // it will not return anything because every number based will be converted to string. | ||
| // =============> Write your prediction here | ||
|
|
||
| //const num = 103; | ||
| const num = 103; | ||
|
|
||
| //function getLastDigit() { | ||
| // return num.toString().slice(-1); | ||
| //} | ||
|
|
||
| //console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| //console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| //console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
|
|
||
| // Now run the code and compare the output to your prediction | ||
| // =============> The last digit of 42 is 3 three times. | ||
| // the prediction was close but not accurate, the case is that the parameter num needs to be | ||
| //the function instead of const num = 103. | ||
| // =============> | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
| function getLastDigit(num) { | ||
| function getLastDigit() { | ||
| return num.toString().slice(-1); | ||
| } | ||
|
|
||
| console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
|
|
||
| // Now run the code and compare the output to your prediction | ||
| // =============> write the output here | ||
| // Explain why the output is the way it is | ||
| // =============> write your explanation here | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
| // This program should tell the user the last digit of each number. | ||
| // Explain why getLastDigit is not working properly - correct the problem | ||
| // parameter num needs to be with the getLastDigit function instead of const num=103. |
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.
I was referring to the operation that increase the value of a variable by 1. For example,
count = count + 1.Can you look up the name of such operation?