-
-
Notifications
You must be signed in to change notification settings - Fork 337
Sheffield| 26-ITP-Jan| Mona-Eltantawy | Sprint 2 | Coursework/sprint 2 #1227
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
f18f2af
e3e39a8
e11ca35
89c0e11
a23c098
58ecfb8
7bc4f5d
2e5854e
9d762f3
1d7c01b
6fe47f8
956c1b0
9027d5d
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,7 +1,8 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
| =============> write your prediction here: the error will occur because the variable decimslNumber gevine a value of 0.5 | ||
| with a const declaration and this will make an error if the brograme given a diffrent value for the decimalNumber. | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
|
|
@@ -14,7 +15,18 @@ function convertToPercentage(decimalNumber) { | |
|
|
||
| console.log(decimalNumber); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your explanation here | ||
| when the program run it give a SyntaxError: Identifier 'decimalNumber' has already been declared. This is because the variable decimalNumber is declared twice in the function | ||
| convertToPercentage, and inside the function with the constant varible it redeclared again also using the function name decimalNumber with the console.log function will give an error because the function name should be | ||
| to fix this error we can remove the const variable declaration of decimalNumber from the function and use the function name | ||
| 'ConvertToPercentage' to recall the function and pass the value of the decimalNumber.CSSStyleDeclaration | ||
|
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.
|
||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function convertToPercentage(decimalNumber) { | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(convertToPercentage(0.5)); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| I prediact that the error will occur because the function multiply does not return any value and this will make the console.log function to print undefined instead. | ||
|
|
||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
|
|
@@ -9,6 +11,21 @@ function multiply(a, b) { | |
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| when the program run it give this output: | ||
|
|
||
| 320 | ||
| The result of multiplying 10 and 32 is undefined | ||
|
|
||
| 320: the out put for the console.log inside the function | ||
|
|
||
| while the ouout the out put for the console.log function out of the function returned the string provided in the function and an undefiened because the function multibly doesn't return any value. | ||
| to fix this error we need to change the console.log function inside the multiply function to return. | ||
|
Comment on lines
+21
to
+22
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 have probably figured out the bug, but I can't quite get what this sentence mean. |
||
|
|
||
|
|
||
| // 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 |
|---|---|---|
|
|
@@ -15,5 +15,10 @@ | |
| // It should return their Body Mass Index to 1 decimal place | ||
|
|
||
| function calculateBMI(weight, height) { | ||
| let BMI = weight / (height ** 2); | ||
| return BMI.toFixed(1); | ||
|
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 type of value do you expect your function to return? A number or a string? Different types of values may appear identical in the console output, but they are represented and treated differently in the program. For example, console.log(123); // Output 123
console.log("123"); // Output 123
// Treated differently in the program
let sum1 = 123 + 100; // Evaluate to 223 -- a number
let sum 2 = "123" + 100; // Evaluate to "123100" -- a string. |
||
| } | ||
|
|
||
| console.log(calculateBMI(80, 1.7)); | ||
|
|
||
| // return the BMI of someone based off their weight and height | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,24 @@ | |
| // You will need to declare a function called toPounds with an appropriately named parameter. | ||
|
|
||
| // You should call this function a number of times to check it works for different inputs | ||
|
|
||
| function toPounds(penceString) { | ||
| const penceStringWithoutTrailingP = penceString.substring( | ||
| 0, | ||
| penceString.length - 1 | ||
| ); | ||
|
|
||
|
|
||
| const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
| const pounds = paddedPenceNumberString.substring( | ||
| 0, | ||
| paddedPenceNumberString.length - 2 | ||
| ); | ||
|
|
||
| const pence = paddedPenceNumberString | ||
| .substring(paddedPenceNumberString.length - 2) | ||
| .padEnd(2, "0"); | ||
| return `£${pounds}.${pence}`; | ||
| } | ||
|
Comment on lines
+8
to
+25
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. Indentation is off. Have you installed the prettier VSCode extension and enabled "Format on save/paste" on VSCode, |
||
|
|
||
| console.log(`£${pounds}.${pence}`); | ||
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.
This sentence is quite long, and without punctuation marks it is not easy to read. Can you revise it?