Question: Create JavaScript, HTML, and CSS pages: Create a webpage that calls your function from the source code to perform a calculation. Use the MonthlyPayment Example

Create JavaScript, HTML, and CSS pages:

  • Create a webpage that calls your function from the source code to perform a calculation.
  • Use the MonthlyPayment Example as a model.
  • Include an h1 header to let the user know the purpose of the page.
  • In all of the HTML, CSS, and JavaScript files, include source code comments and headers with your name, project number, and submit date.
  • Your function should not access any HTML controls, it should accept its inputs as parameters, and return the result of the calculation, for example:
    function in2cm(inches) { var cm = inches * 2.54; return cm; } 
  • Enter the inputs to the function in textfields.
  • Display the output in a textfield.
  • Include labels and possibly instructions to make the use of your user interface clear to the user.
  • Use an external CSS stylesheet to set the fonts and colors.
  • All of your JavaScript code should be in an external script file with the extension .js. In particular, don't use inline JavaScript code like this:
    Instead, to add an event handler to a control, use
    var button1 = document.getElementById("btn1"); button1.addEventHandler("click", eventHandler); 
    or
    var button1 = document.getElementById("btn1"); button1.onclick = eventHandler; 
  • Include this line at the bottom of your script:
    window.addEventListener("load", "init"); 
  • Include a link back to the projects page.
  • Don't use the name attribute to access HTML controls, use the id attribute with getElementById. The name attribute is for server-side programming.
  • Use an external stylesheet your your HTML page. Don't use document-level of inline styles except in special cases. Also don't use deprecated HTML styles.

Source Code:

*Also fix the source code: Imaginary roots handled correctly, but real roots are not. Use an array to return the real roots or use a string as you did with the imaginary ones."

JavaScript:

// Javascript code for calculating quadratic equation roots from values of coefficients from use throughout the prompt box.

// JavaScript function to calculate roots of Quadratic equation.

function quadRoots (a,b,c) {

var firstRoot, secondRoot;

// calculating discrminant

var disc = b * b - 4 * a * c;

// checking for real and different roots

if (disc > 0) {

firstRoot = (-b + Math.sqrt(disc)) / (2 * a);

secondRoot = (-b - Math.sqrt(disc)) / (2 * a);

// showing result

return (firstRoot, secondRoot);

}

// checking for real and equal roots

else if(disc == 0) {

firstRoot = secondRoot = -b / (2 * a);

// showing result

return (firstRoot, secondRoot);

}

// checking if roots are not real

else {

let real = (-b / (2 * a)).toFixed(2);

let imaginary = (Math.sqrt(-disc) / (2 * a)).toFixed(2);

return (`The roots of quadratic equation are ${real} + ${imaginary}i and ${real} - ${imaginary}i` );

}

}

//take input from the user using prompt

let a = prompt("Please enter the first number: ");

let b = prompt("Please enter the second number: ");

let c = prompt("Please enter the third number: ");

result = quadRoots(a, b, c);

alert(result);

// Javascript function for calculating passer rating is below:

// Here are hardcoded values that are passed as inputs in function arguments and documents. write() is used to show the results.

// Defining function for calculating passer rating

function calcPassrating (completions, yards, attempts, touchdowns, interceptions) {

var a = ((completions / attempts) - 0.3) *5

var b = ((yards / attempts) - 3) * 0.25

var c = (touchdowns / attempts) * 20

var d = 2.375 - (interceptions / attempts) * 25

var PasserRating = ((a + b + c + d) / 6) * 100;

return PasserRating;

}

// Giving hardcoded values as arguments.

var completions = 3.45;

var yards = 20;

var attempts = 3;

var touchdowns = 7;

var interceptions = 4;

// Calling the Function.

var result = calcPassrating(completions, yards, attempts, touchdowns, interceptions);

// Using document.writeln() to show result

document.writeln("The result is " + result);

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!