Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

a. What are S, F, and P?

Answered: 1 week ago

Question

Prepare an electronic rsum.

Answered: 1 week ago

Question

Strengthen your personal presence.

Answered: 1 week ago

Question

Identify the steps to follow in preparing an oral presentation.

Answered: 1 week ago