-
-
Notifications
You must be signed in to change notification settings - Fork 336
Glasgow | 26-ITP-Jan | Joma Alrzini | Sprint 2 | Coursework #1060
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
2dc31c3
cb70a21
d0df081
1de86ca
2706654
da626b2
433e170
632f5be
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,13 +1,28 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| /// This code will error before it runs. 'str' has already been declared" | ||
| // | ||
| // This happens because: | ||
| // 1. 'str' is already declared as a function parameter | ||
| // 2. Inside the function, we try to declare 'str' again using 'let' | ||
|
|
||
| // original code | ||
| //function capitalise(str) { | ||
| //let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| //return str; | ||
| //} | ||
|
|
||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
| // write your explanation here | ||
| //When you write: function capitalize(str) | ||
| // - 'str' is already declared as a parameter | ||
| //Then inside the function: let str = ... | ||
| // - This tries to declare 'str' again | ||
|
|
||
| // new code | ||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| let capitalised = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return capitalised; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your new code here | ||
| console.log(capitalise("hello")); // "Hello" | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,15 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
| // decimalNumber is already declared as a function parameter. and name variable the same | ||
|
|
||
| // 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); | ||
|
|
||
| // =============> write your explanation here | ||
| console.log(convertToPercentage(0.5)); | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // creates a function named convertToPercentage | ||
| // The function returns the percentage string.SS |
|
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 didn't write tests for your fix.
Author
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. I added the test
Author
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. Kindly mark this as complete if there is no further change needed |
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.
Kindly revisit this file to make it clearer. Leave the comments on the original code.