diff --git a/Q1.js b/Q1.js new file mode 100644 index 0000000..2af5343 --- /dev/null +++ b/Q1.js @@ -0,0 +1,33 @@ +//I wan a function that takes 2 numbers and adds them. +//INPUT: two numbers, num1 and num2 +//OUTPUT: a new number which is the result of the calculation +//in this case, examples are num1 = 5: num2 = 5: result = 10 + +function myFunction(num1, num2) { + return num1+num2 + + } + const result = myFunction(5,5) + console.log(result) + + + // I want a function that takes 2 numbers, adds them, then multiplies the result by the same 2 numbers + +// INPUT: two numbers, num1 and num2 (I choose the variable name) +// OUTPUT: a new number that is the result of a calculation +// EXAMPLES: num1 = 2; num2 = 3; result = 30 +function doCalculation(num1, num2) { + result = 0; + // each step should be 1 single action: a push(), a get of a value, a for looop initialisation, an if statement + // done: step 1: adds the two numbers + result = num1 + num2; + console.log("Adding:", result); + //done: step 2: multiply the current result by num1 and num2 + result = result * num1 * num2; + console.log("Multiplying:", result); + //done: step 3: return the result + return result; + } + + result = doCalculation(2, 3); + console.log(result); \ No newline at end of file diff --git a/README.md b/README.md index 5cee675..8b59569 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Your instructor will demonstrate this process for the first question. ### Q1 What is the value of `result` after calling this function? Why? - +// num1 and num2 will add together. this is because the return function has + ```javascript function myFunction(num1, num2) { return num1+num2 @@ -50,7 +50,7 @@ const result = myFunction(5,5) ### Q2 What is the value of `result` after calling this function? Why? - +it will be the same as the previous as you specify it in the {} ```javascript function myFunction(num1, num2) { num1+num2 @@ -61,7 +61,7 @@ const result = myFunction(5,5) ### Q3 What is the value of `num` at the end of the program? Why? - +it will be 9 because num is equal to 10 and only when the function is called will it evaluate the delcared num=10 ```javascript function myFunction(num) { return num-1 @@ -74,7 +74,7 @@ num = myFunction(num) ### Q4 What is the value of `add` and `num` at the end of the program? Why? - +num will be 9 and add will add be 9 aswell as it will = to my function which after operating will be 9 ```javascript function myFunction(num) { return num-1 @@ -88,7 +88,7 @@ add = myFunction(add) ### Q5 What value will be logged inside the function call? Why? - +2 because nothing aside from that is in the {} ```javascript function myFunction(num, num1) { console.log(num1) @@ -114,7 +114,6 @@ let num1 = 2 myFunction(num1, num) ``` - ### Q7 What will the value of counter be at the end of this program? Why?