-
-
Notifications
You must be signed in to change notification settings - Fork 335
Sheffield | 26-ITP-Jan | Seti Mussa | Sprint 2 | Coursework #1217
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 6 commits
5abf1f5
045a934
6b5e82d
a625e69
9b3eb4b
41d76e2
dee92a3
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,20 +1,29 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
| // The program will give a SyntazError because a number (3) is used as peramter name in the function. | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
| // My perdiction is that program will not run and show a SyntaxError because 3 is not a valid variable name. | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
| // function square(3) { | ||
| // return num * num; | ||
| // } | ||
|
|
||
| // =============> write the error message here | ||
| // SyntaxError: Unexpected number | ||
|
|
||
| // =============> explain this error message here | ||
| // Funtion parameters must be variable names. | ||
| // You cannot use a number like 3 as name of parameter. | ||
| //Javascript required a valid varible name inside the parentheses. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
| function square(num) { | ||
| return num * num; | ||
| } | ||
|
|
||
|
|
||
| console.log(square(3)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,30 @@ | |
| // 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 | ||
|
|
||
| const toPounds = (kg) => +(kg * 2.20462).toFixed(2); | ||
|
|
||
| const penceToPounds = (p) => `£${(p / 100).toFixed(2)}`; | ||
| const toUpperSnakeCase = (s) => s.toUpperCase().trim().split(" ").join("_"); | ||
| const multiply = (a, b) => a * b; | ||
|
|
||
| // Tests | ||
| console.log(toPounds(10)); // 22.05 | ||
|
|
||
| console.log(penceToPounds(150)); // "£1.50" | ||
|
|
||
| console.log(toUpperSnakeCase("hello there")); | ||
| // "HELLO_THERE" | ||
| console.log(multiply(10, 32)); // 320 | ||
|
|
||
| const convertToUpperSnakeCase = (str) => | ||
| str.toUpperCase().trim().split(" ").join("_"); | ||
|
|
||
| console.log(convertToUpperSnakeCase("hello there")); // "HELLO_THERE" | ||
|
|
||
| // Four functions are implemented because each one performs a specific task. | ||
| // This makes the code easier to read, reuse, and maintain. | ||
| // | ||
| // The penceToPounds function was updated to handle a pence string like "399p". | ||
| // It removes the "p", converts the value to a number, and divides by 100 | ||
| // so the function correctly returns "£3.99".s | ||
|
||
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.
Why implement 4 different functions in this file?
The input to the code in Sprint-1 is a "pence string" in the form "399p" (with a trailing 'p'). The function on line 10 would not work properly if the given
pis a string in this format. Can you update the function accordingly so that your function can return"£3.99"when the given argument is"399p"?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.
Yes, I tested it as you advised me and now it correctly return "£3.99".