Nov
24
2015
By abernal
Functions in java script have the following structure
Syntax
function <nameOfTheFunction> (<parameterA>, <parameterB>, ...) { // Some code here return *some value to return*; }
Sample
function countA () { var phrase = prompt("Type a phrase to be analized"); if ( typeof(phrase) != "string"){ alert("that is not a valid Entry!"); return false; } else { var aCount = 0; for (var index = 0; index < phrase.length; index++){ if (phrase.charAt(index) == "e" || phrase.charAt(index) == "E"){ aCount++; } } alert("There are "+aCount+" A's in : "+phrase+""); return true; } }