-
-
Notifications
You must be signed in to change notification settings - Fork 197
West Midlands | MAY | EMIN AKTURK | Sprint 2 | MODULE-STRUCTURING-AND-TESTING-DATA #691
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
84e3bca
3c9fb3a
c882576
8ccf3b2
d0c0bd7
721fe57
f2f56be
421bdf2
f978685
ed5a1b5
e57d878
f6d89d1
5666561
494b2e5
8cc0f09
5feaf2e
11f7873
29a5ae7
273fafc
cd0d666
7e7357b
1c772e8
aca4c2b
eb244fd
c66c5c6
fde1ec2
9ba099d
70b7e45
d60ad83
db5ec04
203af12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
// I predict the code is for capitalising the first letter of a string. | ||
|
||
|
||
// call the function capitalise with a string input | ||
// interpret the error message and figure out why an error is occurring | ||
|
||
function capitalise(str) { | ||
// the error is "The symbol "str" has already been declared." | ||
|
||
/* function capitalise(str) { | ||
let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return str; | ||
} | ||
|
||
*/ | ||
// =============> write your explanation here | ||
// Error occurs because the str was mentioned as a parameter in the definition which is already a variable name in the function body. | ||
|
||
// =============> write your new code here | ||
|
||
function capitalise(str) { | ||
const capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return capitalisedStr; | ||
} | ||
|
||
// to call the function : | ||
|
||
console.log(capitalise("naber?")); // Output: "Naber?" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
// Predict and explain first... | ||
|
||
// =============> write your prediction here | ||
// =============> My prediction is code wont return anything because the function does not have a return statement. | ||
|
||
function multiply(a, b) { | ||
/* 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 | ||
console.log(`The result of multiplying 10 and 32 is `${multiply(10, 32)}`); | ||
*/ | ||
// =============> Once return statement is added, it will return the result of the multiplication. | ||
|
||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
// =============> | ||
|
||
function multiply(a,b) | ||
{ | ||
return a*b; | ||
} | ||
|
||
console.log(`result of multiplying 2 times 2 = ${multiply(2, 2)}`); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
// =============> Problem here is that sum does not return no value because return statement and a + b is in different lines. | ||
|
||
function sum(a, b) { | ||
/*function sum(a, b) { | ||
return; | ||
a + b; | ||
} | ||
|
||
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
||
// =============> write your explanation here | ||
*/ | ||
// =============> Once we put a + b back in return statement it will work with no problem. | ||
// 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 45 and 12 is ${sum(45, 12)}`); // Output: "The sum of 45 and 12 is 57" |
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.
What does this output?
Just be careful with formatting too - is there anything that could be improved?