# Javascript Tutorial – 12 – Parameters in Functions

Facebook – https://www.facebook.com/TheNewBoston-464114846956315/

GitHub – https://github.com/buckyroberts

Google+ – https://plus.google.com/+BuckyRoberts

LinkedIn – https://www.linkedin.com/in/buckyroberts

reddit – https://www.reddit.com/r/thenewboston/

Support – https://www.patreon.com/thenewboston

thenewboston – https://thenewboston.com/

Twitter – https://twitter.com/bucky_roberts

Original source

What is wrong with your mic bro

Thanks a million! 🙂

made a bad ass calculator lol

var type = prompt("would you like subtraction, multiplication, addition, etc. please specify");

var x = prompt("Specify first number");

var x2 = prompt("Specify second number");

function add(a,b){

x=a+b;

return x;

}

function sub(a,b){

x=a-b;

return x;

}

function mul(a,b){

x=a*b;

return x;

}

function div(a,b){

x=a/b;

return x;

}

if(type=="addition"){

alert(add(x, x2));

}

if(type=="subtraction"){

alert(sub(x, x2));

}

if(type=="multiplication"){

alert(mul(x, x2));

}

if(type=="division"){

alert(div(x, x2));

}

function add(a,b)

{

x=a+b;

return x

}

var a = prompt("enter a ");

var b = prompt("enter b ");

alert(add(a,b));

—

When I type in 25 first prompt, 25 second prompt, I am getting: 2525 . Why?

Exactly what I was thinking! But i'm a noob so I didn't think it mattered what I thought.

the most comprehensive and interesting javascript tutorial on youtube.

Excellent series

is it ok not to write var x???

Hi guys, any problem with "RETURN"???

function parameter(a,b)

{

x=a+b;

alert(x);

}

parameter(3,5)

Broblem solved 😀

awesomeness

@MegaTeddy000 In 'alert(add(32, 56))' , we tell JavaScript 'Open a popup box and for the value to be displayed, call the add() function with parameters 32 and 56'. So 'function add()' is read & the two numbers are added. Now assume that there is no 'return x' statement. So the addition of 32 & 56 will surely be performed; but the alert does not have a value to display. If you do write 'return x', the sum of 32 & 56 is calculated and returned i.e. alert( add(32,56) ) = alert(88) !

hmm this is like byval and byref in VB

@supersushi269 more extreme:

function hi(x){

for(i=0;i<x;i++){

document.write("!!!1")

}

}

document.write("OMG");

hi(9001);

lol

A real use of functions XD

alert(add(1,add(1,add(1,add(1,add(1,add(1,add(1,add(1,add(1,add(1,add(1,add(1,0)))))))))))));

TRY IT!

@kindofgameplay if you dont tell the function what the return value is, it treats it like a boolean (true or false). giving the variable x, it sends the value of the two numbers added.

@ 3:30 , THAT = 5646

super cool

simplest tutorials for javascript on the web, thanks for all the work man

@zurton ill fast forward a minute into the video and all he has written is var name = greg

View my channel to find a link to my web development blog! I made it to get my ideas out and shows you how to do it. give it a look and make one and blog with me! we can start a little community of bloggers and share ideas! see you soon!

@jowish77 You don't eat heavy meal in the morning, If you are looking for a heavy dinner you don't come here. So if you want more advanced learning, go somewhere else. I find this tut perfect.

I watched all the videos so far . Now I started feeling even if I learn something from u, I may not be able to use it effectively . It is only about spitting out "alert".

I know, this way I can understand the basics fast. But I hardly know, what all I can do with these functions & parameters.

This tutorial will not help u understand the actual usage of these powerful tools. We can't grow beyond "alert".

sorry bro.. 🙂

@gorospakabum I think it's the same thing. I use var x = a + b; It will help me to not be confused later

@zurton <—Hater, why u mad?

goddamn watching your videos is always so painful. how you got to be the most popular "programmer" on youtube is beyond me.

dude u have the best guides ever tysm

Can someone explain why you don't have to declare the variable x? It makes more sense to me that inside the function you had to state:

var x = a + b;

You are a very good teacher. In fact I've seen loads of these tuts and I have to say the usual nerd teaching is garbled to show how clever the teacher is… but in your case you just tell it like it is. Nice one!

Nice!

WOW, how to learn the basics of JavaScript in a couple of hours, invaluable set of videos – Keep up the good work!