-
-
Notifications
You must be signed in to change notification settings - Fork 116
NW-ITP |Mohammed Alzaki | Module-Structuring-and-Testing-Data| Sprint2 | week4 #390
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
07744d9
02b3031
d1ff58c
4e01724
a6f8889
0978670
10837b1
07055e2
e0a8f9c
130149a
1c65aab
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,23 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
|
||
//The variable str has been declared twice the first one as the function | ||
// and the second time inside the function => let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
// call the function capitalise with a string input | ||
// interpret the error message and figure out why an error is occurring | ||
|
||
function capitalise(str) { | ||
/* function capitalise(str) { | ||
let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return str; | ||
} | ||
} */ | ||
|
||
// =============> write your explanation here | ||
// An error occured => SyntaxError: Identifier 'str' has already been declared | ||
//because in javascript we cant declare a variable more than once within scope . | ||
|
||
// =============> write your new code here | ||
function capitalise(str) { | ||
str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return str; | ||
} | ||
|
||
console.log(capitalise("cool")) |
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 fine |
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. Code works fine |
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. Code works fine |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
// Predict and explain first... | ||
|
||
// =============> write your prediction here | ||
//In this function console.log() is used instead of return | ||
|
||
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)}`); | ||
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); */ | ||
|
||
// =============> write your explanation here | ||
|
||
//By using console.log() this multiply function dose not return anything and it just printing the output | ||
//of => a * b to the console + undefined => since console.log does not return | ||
// Finally, correct the code to fix the problem | ||
// 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)}`); |
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. Code works fine |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
//Here we have return; and => a + b ; in seprate lines closed with semicolon. | ||
|
||
function sum(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 | ||
//AS we know that return end and stops the execution of the function witch mean that => a + b | ||
//will not be executed and line 8 is useless since the function stops at line 7. | ||
|
||
// 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)}`); |
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. Code works fine |
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. code works fine |
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. code works fine |
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. code works fine - my IDE showed one minor syntax consideration ; should be at the end. Also briefly summarise the code process in about 3 lines. |
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 looks fine |
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.
This works fine