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 responses to “Javascript Tutorial – 12 – Parameters in Functions”

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

  2. 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?

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

  4. 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!

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

  6. 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.. ๐Ÿ™‚

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