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

30 thoughts on “Javascript Tutorial – 12 – Parameters in Functions

  • November 6, 2017 at 12:00
    Permalink

    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));
    }

  • November 6, 2017 at 12:00
    Permalink

    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?

  • November 6, 2017 at 12:00
    Permalink

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

    function parameter(a,b)
    {
    x=a+b;
    alert(x);
    }
    parameter(3,5)

    Broblem solved ­čśÇ

  • November 6, 2017 at 12:00
    Permalink

    @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) !

  • November 6, 2017 at 12:00
    Permalink

    @supersushi269 more extreme:

    function hi(x){

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

    document.write("!!!1")

    }

    }

    document.write("OMG");
    hi(9001);

    lol

  • November 6, 2017 at 12:00
    Permalink

    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!

  • November 6, 2017 at 12:00
    Permalink

    @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.

  • November 6, 2017 at 12:00
    Permalink

    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!

  • November 6, 2017 at 12:00
    Permalink

    @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.

  • November 6, 2017 at 12:00
    Permalink

    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.. ­čÖé

  • November 6, 2017 at 12:00
    Permalink

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

  • November 6, 2017 at 12:00
    Permalink

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

  • November 6, 2017 at 12:00
    Permalink

    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;

  • November 6, 2017 at 12:00
    Permalink

    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!

Leave a Reply