JavaScript functions (reusable blocks of code) Programs
1. Define a function welcome() to alert "Welcome to Javascript Programming!" and call from body section of the html.
View     Try It
2. Define a function welcome() with name parameter to alert "name + ", Welcome to Javascript Programming!" and call with argument from body section of the html.
View     Try It
3. Ask user to enter name and define a function welcome() to alert "username + ", Welcome to Javascript Programming!" and call from body section of the html.
View     Try It
4. Define a function sum() with two parameters num1, num2 to return sum of the two numbers and call from body section of the html.
View     Try It
5. Develope a milage calculation application using functions. Ask user to enter distance travelled and petrol consumed.
Define a function mileage(distance, petrol) to calculate mileage = distance travelled/petrol consumed. Display the output as follows:
Your mileage is [millage] kms per liter.
View     Try It
6. Develope a arthimetic operations application using functions. Define Addition, substraction, Multiplication and Division functions.
Ask user to "Enter 1 for Addition, 2 for substraction, 3 for Multiplication and 4 for Division"
Get the two numbers to perform arthimetic operation. Call appropriate function using selection logic.
View     Try It
7. Develope a financial calculations application using functions. Define bonus, simple interest, and future value functions.
Ask user to "Enter 1 for Bonus, 2 for Simple Interest , 3 for Future value"
Call appropriate function using selection logic.
View     Try It
8. Develope a geometry calculations application using functions. Define area of Circle,area of Rectangle , area of Triangle and area of Square functions.
Ask user to "Enter 1 for area of Circle, 2 for area of Rectangle , 3 for area of Triangle and 4 for area of Square"
Call appropriate function using selection logic.