From 016fdd3566025c414eebcd90a21fdbab0088e498 Mon Sep 17 00:00:00 2001 From: Nozie Date: Wed, 14 Sep 2022 17:05:08 +0100 Subject: [PATCH 1/3] so far --- Q1.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Q1.js diff --git a/Q1.js b/Q1.js new file mode 100644 index 0000000..423f930 --- /dev/null +++ b/Q1.js @@ -0,0 +1,28 @@ +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 From 0115bb7ef5556bd4fc99b1cc57f44106f3a78374 Mon Sep 17 00:00:00 2001 From: Samuel Odigie Date: Wed, 14 Sep 2022 17:51:03 +0100 Subject: [PATCH 2/3] some done --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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? From 06f87e8efc4937b6fceee1e40e2fd2fe274fd627 Mon Sep 17 00:00:00 2001 From: Nozie Date: Thu, 15 Sep 2022 09:16:53 +0100 Subject: [PATCH 3/3] q1 --- Q1.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Q1.js b/Q1.js index 423f930..2af5343 100644 --- a/Q1.js +++ b/Q1.js @@ -1,3 +1,8 @@ +//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