Question
Please write JavaScript code for the exercises listed below. PLEASE document the code with comments for code management. Exercise 1 - Simple Function Create a
Please write JavaScript code for the exercises listed below. PLEASE document the code with comments for code management.
Exercise 1 - Simple Function
Create a function called greet that has one parameter called name and does not return a value. When greet is called, it should say helloto the value passed in as the argument to name. For instance, greet("Bob"); should print out Hello, Bob!
You can either get a name from the user, or hard-code one directly into your program.
Exercise 2 - Mathematical Functions
In this problem, you will define a set of mathematical functions and then use them to calculate a value.
- Write a function called multiply that takes two parameters, n and m, and returns the product of n and m.
- Write a function called add that takes two parameters, n and m, and returns the sum of n and m
- Write a function called square that takes one parameter, n, and returns the value of that number times itself.
- Your square function should make use of the multiply function that you define in step 1
- Write a function called calculate_quadratic that uses the functions defined in steps 1, 2, and 3 and calculates the value of the quadratic equation: a*x^2 + b*x + c
- You will ask the user for the value of a, b, c, and x
- You will use your multiple, add, and square function to calculate the quadratic value
- You will print the calculated value to the console, the document, or with an alert window
Exercise 3 - Tip Calculation
You will write a program that allows a user to see how much they should pay when a tip is included. This will be done in three steps:
- Ask the user for the amount of the bill and the tip percent (as a decimal number, i.e. 20% is 0.20)
- Write a function that will calculate and return the amount that should be paid as a tip for a restaurant bill.
- Call your tip calculation function with the bill amount and tip percent as arguments. Using the return value of your tip calculation function, print out both the tip amount and the total of the bill plus the tip.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started