Question: Please write JavaScript code for the exercises listed below. Please Be sure to document the code with comments for code management. Exercise 1 - Simple

Please write JavaScript code for the exercises listed below. Please Be sure to 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 hello to the value passed in as the argument to name. The function should prompt the user for their name and print out, For instance, greet("Bob"); should print out Hello, Bob!

Exercise 2 - Mathematical Functions

In this problem, you will define a set of mathematical functions and then use them to calculate a value. The user should be prompted to give a numbers for n and m for each function and print out the answer for each.

  1. Write a function called multiply that takes two parameters, n and m, and returns the product of n and m.
  2. Write a function called add that takes two parameters, n and m, and returns the sum of n and m
  3. Write a function called square that takes one parameter, n, and returns the value of that number times itself.
    1. Your square function should make use of the multiply function that you define in step 1
  4. 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
    1. You will ask the user for the value of a, b, c, and x
    2. You will use your multiple, add, and square function to calculate the quadratic value
    3. 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:

  1. Ask the user for the amount of the bill and the tip percent (as a decimal number, i.e. 20% is 0.20)
  2. Write a function that will calculate and return the amount that should be paid as a tip for a restaurant bill.
  3. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!