-
-
Notifications
You must be signed in to change notification settings - Fork 195
Glasgow | ITP May -25 | Pandi Simatupang | Module-Structuring-and-Testing-Data | coursework/sprint-2 #650
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?
Glasgow | ITP May -25 | Pandi Simatupang | Module-Structuring-and-Testing-Data | coursework/sprint-2 #650
Changes from all commits
a673f00
95d7600
089cd0a
c18750b
e289031
743e9a8
60dd470
c26acb4
7966e09
83d8bc9
8b56abf
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,21 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
//the function will turn the first given string into Uppercase. | ||
|
||
// call the function capitalise with a string input | ||
// interpret the error message and figure out why an error is occurring | ||
|
||
function capitalise(str) { | ||
let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return str; | ||
let strWithUpperCase = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return strWithUpperCase; | ||
} | ||
|
||
// =============> write your explanation here | ||
// str[0].toUpperCase() ---> gets the first character and uses build-in method to convert a char to uppercase | ||
// str.slice(1) ----> will slice the array or sting "start from 1" to the rest of array or string | ||
// we get an error because we "re-declare" the str variable as parameter and as call back of expression | ||
|
||
// =============> write your new code here | ||
|
||
const myStr = "i forgot add this string"; | ||
console.log(capitalise(myStr)); |
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. For information/reference, when declaring a function we call these parameters, when we call the function we call them arguments. It is a subtle distinction but is important to remember especially when communicating with other developers. |
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 | ||
|
||
// =============> write your prediction of the error here | ||
//the function will return square for every given number. | ||
|
||
function square(3) { | ||
return num * num; | ||
} | ||
// function square(3) { | ||
// return num * num; | ||
// } | ||
|
||
// =============> write the error message here | ||
// ans: Unexpected number | ||
|
||
// =============> explain this error message here | ||
|
||
// ans: function need num to be defined, instead parameter was given 3 as literal value that does not point to any variable as parameter | ||
// Finally, correct the code to fix the problem | ||
|
||
// =============> write your new code here | ||
|
||
function square(num) { | ||
return num * num; | ||
} | ||
|
||
mynum = 3; //define the num | ||
|
||
console.log(square(mynum)); //verify the result |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
// Predict and explain first... | ||
|
||
// =============> write your prediction here | ||
// function will return with result of multiplication of given parameters (i,e: a times b) | ||
// 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 | ||
|
||
// the function does not return any thing, so as result ${multiply(10, 32)} --> will return as "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,23 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
// sure this function wont work because, hang on.. I should predict and pretend that everything is fine | ||
// the function will return with summary of given parameters and console.log will verify it | ||
|
||
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 | ||
//function will execute line the code and escape from the function block whenever it "sees" return.. it will return with any expression put on it | ||
// in this function a+b which is expected as the result is placed after return line because return has ";" so i wont bother look the next line. | ||
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 is important to note that |
||
// just remove the semicolon next to the return.. and put a+b instead, because some how "prettier" as trusty worthy formatter for this course will always add extra ; for every logical expression (somehow).. :) xixixixi | ||
// 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. Can you wrap your code into a function that is then called with the argument |
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.