-
-
Notifications
You must be signed in to change notification settings - Fork 299
London | ITP-Jan-26 | Mohsen Zamani | Sprint 2 | Coursework #913
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
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,7 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
| // =============> Instead of calling the function, a variable is called | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
|
|
@@ -14,7 +14,7 @@ function convertToPercentage(decimalNumber) { | |
|
|
||
| console.log(decimalNumber); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> Also inside the function, decimalNumber is called again | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // =============> decimalNumber = 0.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. Can you correct the function and the code on line 15 so that this script can
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,18 +3,18 @@ | |
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
| // =============> The variable num is not declared | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
|
|
||
| // =============> write the error message here | ||
| // =============>SyntaxError: Unexpected number | ||
|
|
||
| // =============> explain this error message here | ||
| // =============> There must a variable declared, not just simply passing a number as an argument | ||
|
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. Can you find the proper term for the variables defined in a function to accept the passed-in arguments? |
||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
| // =============> function square(num) { | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // =============> the result of the multiply is printed inside function, and at the function call is will be undefined | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> because function is not returning any value | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // =============> return a * b; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,5 +15,8 @@ | |
| // It should return their Body Mass Index to 1 decimal place | ||
|
|
||
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| } | ||
| // return the BMI of someone based off their weight and height | ||
| const 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(70, 1.73)); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,6 @@ | |
| // You will need to come up with an appropriate name for the function | ||
| // Use the MDN string documentation to help you find a solution | ||
| // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase | ||
| function makeUpperSnakeCase(str) { | ||
| return str.toUpperCase().split(" ").join("_"); | ||
|
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. This works. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,11 @@ | |
|
|
||
| function formatAs12HourClock(time) { | ||
| const hours = Number(time.slice(0, 2)); | ||
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| const minutes = time.slice(3); | ||
|
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. We can also use negative indexes (e.g. |
||
| if (hours === 0) return `12:${minutes} am`; | ||
| else if (hours === 12) return `12:${minutes} pm`; | ||
| else if (hours > 12) { | ||
| return `${(hours - 12).toString().padStart(2, "0")}:${minutes} pm`; | ||
| } | ||
| return `${time} am`; | ||
| } | ||
|
|
@@ -23,3 +26,31 @@ console.assert( | |
| currentOutput2 === targetOutput2, | ||
| `current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
| ); | ||
|
|
||
| const currentOutput3 = formatAs12HourClock("00:00"); | ||
| const targetOutput3 = "12:00 am"; | ||
| console.assert( | ||
| currentOutput3 === targetOutput3, | ||
| `current output: ${currentOutput3}, target output: ${targetOutput3}` | ||
| ); | ||
|
|
||
| const currentOutput4 = formatAs12HourClock("12:00"); | ||
| const targetOutput4 = "12:00 pm"; | ||
| console.assert( | ||
| currentOutput4 === targetOutput4, | ||
| `current output: ${currentOutput4}, target output: ${targetOutput4}` | ||
| ); | ||
|
|
||
| const currentOutput5 = formatAs12HourClock("13:06"); | ||
| const targetOutput5 = "01:06 pm"; | ||
| console.assert( | ||
| currentOutput5 === targetOutput5, | ||
| `current output: ${currentOutput5}, target output: ${targetOutput5}` | ||
| ); | ||
|
|
||
| const currentOutput6 = formatAs12HourClock("01:56"); | ||
| const targetOutput6 = "01:56 am"; | ||
| console.assert( | ||
| currentOutput6 === targetOutput6, | ||
| `current output: ${currentOutput6}, target output: ${targetOutput6}` | ||
| ); | ||
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.
On lines 4 and 17.
The wording is a bit unclear here. Variables are not “called” — functions are called. Can you rephrase it?