/    Sign up×
Community /Pin to ProfileBookmark

JavaScript Functions

So I’ve been having some issues with homework, and I’ve tried various methods trying to find my way around this but can’t seem to find the correct way. It should be simple for those who are knowledgeable in JavaScript as this is what’s currently being taught in my intro course.

Instructions:

Complete the function foo below. Make it take three parameters and return the result of multiplying the first two and adding the third.

(code given):

function foo(){

}

var n = parseInt(process.argv[2]);
var r = foo(n,n*1,n+2) + foo(n+4,n+5,n+6);
console.log(r);

I understand that the parseInt method is used to gather input, that foo is my function.

I don’t understand how to add parameters correctly, where to add them inside or outside of the function, and how to display them how the instructions direct us to.

Help would be appreciated, thanks in advance!

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@rootOct 13.2016 — Your asking for help with homework which is not going to help you learn.

However, you have the whole arguments thing wrong and the function wrong and nothing would be retirned as you have no return command.

function theFunctionName( the, arguments, here){

// the stuff you want to do in here

}

// calling the function where a,b & c are the values or the data to pass to the function
x = theFunctionName( a, b, c);


As for your question, this can easily be answered and found by proper use of the web browser and asking [b]how do I return a value from a function in javascript[/b] for example...
Copy linkTweet thisAlerts:
@TrainOct 13.2016 — how do I return a value from a function in javascript[/QUOTE]

Google showed me About 59,800,000 results (0.96 seconds)

Google is your friend.
Copy linkTweet thisAlerts:
@JeremyleeauthorOct 13.2016 — For those who are recommending searching on google, thanks, I have. I'm asking for teaching a little on each thing I was lost on. Thank you for the reply ., as your code did help me understand on how to use parameters a little more. I'm a visual learner, so seeing code helps me understand it. Thanks for the replies, anyhow.
Copy linkTweet thisAlerts:
@JeremyleeauthorOct 13.2016 — I'm stuck on another task given over the same lesson, you can see the instructions listed in the commented code, and my attempt to complete the instructions in-between the comments.

http://prntscr.com/ctforr

The current output when running the program vs the reference sheet it's intended on matching:

http://prntscr.com/ctfpbg

If someone could hint at what I'm doing wrong, I would appreciate it. I'm not asking for an answer, just to know what I'm doing right and what I'm wrong on. Thank you!
Copy linkTweet thisAlerts:
@Benur21Oct 14.2016 — Scratch has good ways to learn how functions and parameter works.
Copy linkTweet thisAlerts:
@rootOct 15.2016 — You haven't learnt anything from the comment I made, when you pass something but don't have a variable in the function that uses the passed data, your not understanding how a function works.

Example.
function addThem(a, b){
return a + b;
}

result=addThem("Cheese", 6);

alert( result );
will output Cheese6 in a pop up alert box.

It really isn't that hard to understand functions.
×

Success!

Help @Jeremylee spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...