0

I have a function, functionOne, defined normally, outside of other functions or if statements. Now I have another function, functionTwo, and I call functionOne inside of functionTwo. I've tried searching around but I could only find things that told me to define functionOne inside of functionTwo. My issue is that it's already defined, outside of any functions, as I said before.

Here's my code:

function functionOne (connection) {
//code here for functionOne
}

function functionTwo (functionOne, connection) {
//some code here for functionTwo

functionOne(connection)
}

The error is that the connection var isn't being passed over. Any fixes appreciated! Thanks :)

6
  • you aren't defining functions correctly. should be: function <functionName> () {} Commented Oct 28, 2017 at 16:07
  • if you run this code, what error message do you get? :) Commented Oct 28, 2017 at 16:07
  • @hackerrdave sorry I messed up in the question, I did actually do that I just forgot to add it there my bad :P Commented Oct 28, 2017 at 16:34
  • what do you mean by "connection var isn't being passed over"? how are you invoking functionTwo ? Commented Oct 28, 2017 at 16:47
  • 1
    @hackerrdave OHHHHH I didn't pass functionOne as a parameter when invoking functionTwo.... hehe got it fixed now thanks :P Commented Oct 28, 2017 at 16:53

2 Answers 2

1

to define a function you should use this syntax:

function funcName(args){
    //code
}

here in your example you did not define any function. you just called functions that don't exist.

Sign up to request clarification or add additional context in comments.

3 Comments

sorry I messed up in the question, I did actually do that I just forgot to add it there my bad :P
then you don't need to pass functionOne as an argument to functionTwo
Thanks but I've already got it figured out in the comments of the original question :)
0

If I am understanding your question you just need to provide the argument(s) for the first function within in the second

   function funcOne(a){
    return a
}

function funcTwo(b, c){
    //funcTwo's value of "b" will be used for funcOne as the "a" argument
    return funcOne(b) + c
}

console.log(funcTwo(3,4)) //returns 7

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.