Results 1 to 5 of 5

Thread: JavaScript - functions

  1. #1
    Join Date
    Dec 2013

    JavaScript - functions

    Just started a javascript course. What is the benefit of using a function for the following script. Verses living the function off. It appears to do the same thing.

    <title> Greeting </title>
    function greet(who){
    alert ("Hello, "+ who + '' + who2);
    var who = prompt ("what is your first name");
    var who2 = prompt ("what is your last name");
    alert("Hello " + who + ' ' + who2);

  2. #2
    Join Date
    Dec 2005
    It does not do the same thing.

    You NEVER call the function, so it does nothing!

  3. #3
    Join Date
    Oct 2013
    This fill you in : http://jsfiddle.net/wTBqW/

  4. #4
    Join Date
    Mar 2007
    Functions are good for helping you reuse code blocks that do specific tasks without having to write the code again and again, you just call a function and the interpreter then fetches that code block, runs it and the output is then generated if any output is needed, etc.

    Functions are your friend
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  5. #5
    Join Date
    Oct 2013
    From the Kindle edition of my book, "A Smarter Way to Learn JavaScript":

    A function is a block of JavaScript that robotically does the same thing again and again, whenever you invoke its name. It saves you repetitive coding and makes your code easier to understand.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles