JavaScript Cheet Sheet

1.5 - Functions

// When sayHello() is called it displays an alert
// This sayHello() is called when you click the example button using 'onclick' method

function sayHello(){
   alert("Hello, I'm from a function. Thanks for calling.");
}
/// When square() is called it prompts the user for an input // squareIt() is later called with the user's input as the argument. squareIt() function requires parameter 'input' and returns the input (a number) multiplied by itself to square the value.

function square(){
var input = prompt("Enter a number to square");

   function squareIt(input){
     return input*input;
   }

alert(input +" squared is " +squareIt(input));
}