Passing-values-to-functions-with-arguments

Passing-values-to-functions-with-arguments
0.0 0

#1

Usually I figure out things on my own but I have tried everything I can think of but to no avail. If someone can please tell me what I am doing wrong. I have spent so much time on this…

When defining the function I had (1, 2) (7,9) and different variations of that. The example makes sense but I do not know how to proceed given the task requests 2 separate arguments. My previous attempts were probably closer to the correct code but I am at my wits end.

// Only change code below this line.
function functionWithArgs[(a,b)(c,d)] {
  console.log(1 + 2) (7 + 9);
}
functionWithArgs(3, 16);

Your code so far



// Example
function ourFunctionWithArgs(a, b) {
  console.log(a - b);
}
ourFunctionWithArgs(10, 5); // Outputs 5

// Only change code below this line.
function functionWithArgs[(a,b)(c,d)] {
  console.log(1 + 2) (7 + 9);
}
functionWithArgs(3, 16);


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36.

Link to the challenge:


#2

its a very easy one actually .I just solved it in 8 sec just for check purpose of you confusion. :smile:
The challenge just says to make function named "functionWithArgs" and then pass two argument,
lets name them "i" and "j" so now we have : functionWithArgs(i,j) . then it says to just sum up the the arguments and output it; so we do :

function functionWithArgs(i ,j){
  console.log(i+j);
}

And at last they tell us to call the function with two number(any number you wish) in it to just check whether its working or not. So we do that :

functionWithArgs(12,12);

And there we go. Bingo :blush:


#3

I entered what you sent me and it works BUT I HAVE NO IDEA where you got the 12 from :zipper_mouth_face:

Can you please explain this to me. I never would have gotten this code. I was going about it the wrong way for some reason. I thought I had to do something else. >.<


#4

THIS confused me


functionWithArgs(1,2) should output 3
functionWithArgs(7,9) should output 16

#5

When you are defining a function, you can specify variables for that functions scope. The variables will only be available within that function while it is executing. In your example these variables are i and j. You can use these variables inside the function. When you declare your function, the order you place values between the () determines which variable they are assigned to.

functionWithArgs(1,2);
// i is equal to 1
// j is equal to 2
// console.log will log the operation of i (1) + j (2) to the console

Note
The function is not returning these values, it is using the console.log() method to log the result of the operation to the console. You could not store the result of the function (i.e. in a variable or use it in an if() conditional) as it is.

Arguments are also called parameters.


#6

okey the main problem is that you are overthinking on algorithms .I suffer from that too sometimes.
So there’s nothing hard here. you pass any number as arguments you want. In my code i pass 12 and 12 which will print out 24.
And about the examples
it passes 1 and 2 :
functionWithArgs(1,2) should output 3
cause 1+2=3
And same goes with other one. these are very easy actually.just dont over think. take simple steps when solving algorithms. You can do it .:slight_smile: