Blake
Blake

Reputation: 3

Storing functions within arrays

I'm having a issue with something very simple. I am just wondering as to I can store these functions within an array. Check out some of the code below. I am unsure as to if this is correct as to how I am storing these functions. I am unsure as to if these functions should be within a object literal or array.This is not necessarily for a project, just good practice. Thanks!

//declaring a function 
function alert_name(){
    //declaring variables within a function asking user their name.
    var username =  prompt("Hey there, what is your name."," ");
//generating user input
    var chameleon = "Welcome " + username;
//combinators 
    //alert("Welcome " + chameleon+ ", This is 'the website");
};
// inserting quotes into a string that is being alerted from the browser.
function otherTHings(){
    var single = 'He said \'RUN\' ever so softly.';
    //alert(single);
};
//running these functions and actually carry out the operations 
//that have actually been declared into code above. 

//string operations
function string_opertaions(){
    var complete = "Com" + "plete";
    //alert(complete);
    // using combinators to do the same thing. 
    var sentance1 = "My name is";
    var sentance2 = "someone";
    var  totalsenatces = sentance1 += sentance2;
    //alert(totalsenatces);
};

//Booleans or true false values
function booleanys(){
    var lying = false;
    var truthful = true;
};
//Arrays very important. very similar to a object literal but different.
//Arrays store information or values or varibales/data. 
var rack = [];
rack[0] = alert_name();
rack[1] = otherTHings();
rack[2] = string_opertaions();
rack[3] = booleanys();
//alert_name();
//otherTHings();
//string_opertaions();
//booleanys();

Upvotes: 0

Views: 34

Answers (1)

Daniel A. White
Daniel A. White

Reputation: 190945

You are invoking the function and storing the result!

var rack = [];
rack[0] = alert_name;
rack[1] = otherTHings;
rack[2] = string_opertaions;
rack[3] = booleanys;

Upvotes: 1

Related Questions