Repository navigation
London | 26-ITP-Sep | Abakar Souleyman | Sprint 3 | Coursework #1583
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 17 commits
3bdfb60
15e3b83
a44bb25
c5a6226
052c090
d6eb93e
5afd460
a379651
e9fda63
f0201dd
c4470d9
add8d2e
73113c5
fc9a860
6501234
65e5b19
1b143ad
2583b44
b124f10
286c2a2
ff0eee9
62e622c
60be8e2
862d481
a4a378f
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,19 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| //- we expect a syntaxerror because "str" is already declared as function parameter and again as a variable within the same function scope. | ||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
| //"Error: SyntaxError: Identifier 'str' has already been declared" why: because "str" declared twice. | ||
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
| // function capitalise(str) { | ||
| // let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| // return str; | ||
| // } | ||
|
|
||
| // =============> write your explanation here | ||
| //- I changed the variable name to "strg" to avoid the error. | ||
| // =============> write your new code here | ||
| function capitalise(str) { | ||
| return `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| } | ||
| console.log(capitalise("abakar")); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,33 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| //- variable name "decimalNumber" declared twice in the same function. one as function parameter and again as a const in the same function. | ||
| // =============> write your prediction here | ||
|
|
||
| //- SyntaxError because "decimalNumber" declared twice. | ||
| // 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 | ||
| // I moved `const decimalNumber = 0.5` outside the function. The function already has `decimalNumber` as a parameter, so I can pass a number directly when calling it, like `convertToPercentage(7)`. The function then multiplies it by 100 and adds `%`. | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
| const 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. Line 27 uses
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. It uses the parameter defined on line 25. Since we’re not using the previously declared value of 0.5, I removed it as it was unnecessary.
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. Right, it uses the parameter. Fixed. |
||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
|
|
||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(decimalNumber); | ||
| console.log(convertToPercentage(7)); | ||
|
|
||
| // =============> write your explanation here | ||
|
|
||
| // 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,27 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
| //we are giving a value for the input instead of name that can hold different values. | ||
|
|
||
| // =============> write your prediction of the error here | ||
| //syntaxerror related to the function input "(3)" | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
| // function square(3) { | ||
| // return num * num; | ||
| // } | ||
|
|
||
| // =============> write the error message here | ||
|
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 answer is still empty. Your prediction on line 8 says SyntaxError. Was that right? Write the error name here.
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. updated the error message.
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. That's the one. Fixed. |
||
|
|
||
| // =============> explain this error message here | ||
|
|
||
| // we gave a placeholder for the function instead of value that can't be changed. | ||
| // 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 |
|---|---|---|
| @@ -1,14 +1,21 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| //- "a and b" are defined as parameters and receive 10 and 32. The function calculates and logs 320, but it doesn't return the value. Because there is no return, the function call evaluates to undefined. | ||
|
|
||
| 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)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| //- Added a return statement so the function returns the result to the function call. The console.log() is just printing 320 and function doesn't give 320 back and thats why "${multiply(10, 32)}" gets undefined. | ||
|
|
||
| // 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,21 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| //- return statement in this case stops before it can do the sum of a + b. | ||
|
|
||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
| // function sum(a, b) { | ||
| // return; | ||
| // a + b; | ||
| // } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| // console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| //- added a + b to return so function returns the sum. | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
| function sum(a, b) { | ||
| return a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,23 +2,43 @@ | |
|
|
||
| // Predict the output of the following code: | ||
| // =============> Write your prediction here | ||
| //-getting the last digit of 103 | ||
|
|
||
| const num = 103; | ||
| // const num = 103; | ||
|
|
||
| function getLastDigit() { | ||
| return num.toString().slice(-1); | ||
| } | ||
| // 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)}`); | ||
| // 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 | ||
| //-The last digit of 42 is 3 | ||
| //-The last digit of 105 is 3 | ||
| //-The last digit of 806 is 3 | ||
|
|
||
| // Explain why the output is the way it is | ||
| // -Every time the function calls 103 | ||
| // =============> 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 | ||
| //-The function was looking at the outside "num" but Now there are two (num) one outside the scope "const num= 103" and i added another inside the function scope. | ||
| //-The function calculates something and returns it then console.log outside receives that returned value and prints it. | ||
|
|
||
| const num = 103; | ||
|
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. Is
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 removed the unnecessary const num = 103 because the function already receives num as a parameter.
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. Fixed. Good. |
||
|
|
||
| function getLastDigit(num) { | ||
| 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)}`); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,9 @@ | |
| // 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 convertToUpperCase(sentence) { | ||
|
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. Function names should tell others what the function does. If you use
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. Changed to " toUpperSnakeCase " which I think is more descriptive and closely related to what the function does.
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.
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. Good name. Fixed. |
||
| return sentence.toUpperCase().replaceAll(" ", "_"); | ||
|
|
||
| } | ||
| console.log(convertToUpperCase("welcome to Chad")); | ||

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.
Your code on line 17 doesn't use
strgany more. Does line 14 still describe your fix? Update it to match.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.
updated the explanation on line 14.
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.
Line 14 matches your code now. Good.