Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// Your Name // Calculated values: var discriminant; var complexSolutionRealPart; var complexSolutionImaginaryPart; var realSolution1; var realSolution2; // String literals: var sDiscriminant1 = The value of

// Your Name

// Calculated values: var discriminant; var complexSolutionRealPart; var complexSolutionImaginaryPart; var realSolution1; var realSolution2;

// String literals: var sDiscriminant1 = "The value of the discriminant is "; var sDiscriminant2 = "Since the value of the discriminant is "; var sInvalidInput = "A number must be entered for each coefficient."; var sSolutions1 = "The soutions are "; var sSolutions2 = "The soution is ";

function onLoadPage() { // You write the code for this function. // Reset all fields:

// Set input focus to the field for "a": }

// Postconditions: // realSolution1 function calculate1RealSolution(a, b, c) { // You write the code for this function. }

// Preconditions: // discriminant // Postconditions: // complexSolutionRealPart // complexSolutionImaginaryPart function calculate2ComplexSolutions(a, b, c) { // You write the code for this function. // Calculate real part:

// Calculate imaginary part: }

// Preconditions: // discriminant // Postconditions: // realSolution1 // realSolution2 function calculate2RealSolutions(a, b, c) { // You write the code for this function. }

function calculateDiscriminant(a, b, c) { // You write the code for this function. }

// Postconditions: // discriminant // complexSolutionRealPart // complexSolutionImaginaryPart // realSolution1 // realSolution2 function calculateSolutions(a, b, c) { discriminant = calculateDiscriminant(a, b, c); if (discriminant > 0) { calculate2RealSolutions(a, b, c); } else if (discriminant == 0) { calculate1RealSolution(a, b, c); } else { calculate2ComplexSolutions(a, b, c); } }

function isNumber(sNumber) { if (sNumber == "") { return false; }

var number = parseFloat(sNumber); if (isNaN(number) == true) { return false; } if (isFinite(number) == false) { return false; } return true; }

// Preconditions: // realSolution1 function output1RealSolution() { // You write the code for this function. }

// Preconditions: // complexSolutionRealPart // complexSolutionImaginaryPart function output2ComplexSolutions() { // You write the code for this function. }

// Preconditions: // realSolution1 // realSolution2 function output2RealSolutions() { // You write the code for this function. }

// Preconditions: // discriminant function outputDiscriminant() { var sOutput = sDiscriminant1 + discriminant + ".
"; if (discriminant > 0) { sOutput += sDiscriminant2 + "> 0, there are 2 real number solutions."; } else if (discriminant == 0) { sOutput += sDiscriminant2 + "= 0, there is 1 real number solution."; } else { sOutput += sDiscriminant2 + "< 0, there are 2 complex number solutions."; } document.getElementById("discriminant").innerHTML = sOutput; }

// Preconditions: // discriminant // complexSolutionRealPart // complexSolutionImaginaryPart // realSolution1 // realSolution2 function outputSolutions() { if (discriminant > 0) { output2RealSolutions(); } else if (discriminant == 0) { output1RealSolution(); } else { output2ComplexSolutions(); } }

function reset() { // You write the code for this function. }

function solve() { // You write the code for this function. // Get field values:

// Validate fields:

// Calculate results:

// Output results: }

function validateFields(a, b, c) { if (isNumber(a) == false) { alert(sInvalidInput); document.getElementById("a").focus(); return false; } if (isNumber(b) == false) { alert(sInvalidInput); document.getElementById("b").focus(); return false; } if (isNumber(c) == false) { alert(sInvalidInput); document.getElementById("c").focus(); return false; } return true; }

Course Project - Guidance ========================= First, study the example output to understand the project's functionality. Next, study the starter files to gain an understanding of their design. HTML file changes ================= For help on the HTML file changes, refer to the following outlines: 01 Getting Started with HTML 02 Integrating Images 05 Formatting Content with Tables 06 Getting User Input with Forms CSS file changes ================ For help on the CSS file changes, refer to the following outlines: 07 Styling Content Using Cascading Style Sheets 08 Advanced CSS JavaScript file changes ======================= For help on the JavaScript file changes, refer to the following outlines: 10 JavaScript (part 1 - Introduction) 10 JavaScript (part 2 - Selection) 10 JavaScript (part 4 - Functions) 10 JavaScript (part 5 - Events) Global variables ---------------- Calculated values: These store the calculated values needed to output the results. String literals: These store the string literals needed to output the results. onLoadPage() function --------------------- To reset all the fields, call the reset() function. To get a reference to field "a", use document.getElementById("a"). To set the input focus to field "a", call its focus() method. calculate1RealSolution() function --------------------------------- This function is called when there is a single real solution. This function must assign its calculated value to the realSolution1 global variable. The calculation formula is: -b / (2 * a) That is, negative b divided by 2 times a. To follow the correct order of operations, use parentheses as shown. calculate2ComplexSolutions() function ------------------------------------- This function is called when there are 2 complex number solutions. This function must assign its calculated real part value to the complexSolutionRealPart global variable. The calculation formula is: -b / (2 * a) That is, negative b divided by 2 times a. To follow the correct order of operations, use parentheses as shown. This function must assign its calculated imaginary part value to the complexSolutionImaginaryPart global variable. The calculation formula is: absolute value(square root(-discriminant)) / (2 * a) That is, the absolute value of the square root of the negative of the discriminant, all divided by 2 times a. Use the Math object function abs() for absolute value. Use the Math object function sqrt() for square root. To follow the correct order of operations, use parentheses as shown. calculate2RealSolutions() function ---------------------------------- The 2 real solutions must be assigned to the global variables realSolution1 and realSolution2. The calculation formulas are: (-b + square root(discriminant)) / (2 * a) and (-b - square root(discriminant)) / (2 * a) That is, negative b plus (or minus) the square root of the discriminant, all divided by 2 times a. Use the Math object function sqrt() for square root. To follow the correct order of operations, use parentheses as shown. calculateDiscriminant() function -------------------------------- This function must return the calculated value of the discriminant. The calculation formula is: (b^2) - (4 * a * c) That is, b squared minus (4 times a times c). To calculate b^2, simply multiply b by b. To follow the correct order of operations, use parentheses as shown. output1RealSolution() function ------------------------------ Define a local variable, say sOutput, and assign it the string concatenation of: sSolutions2, realSolution1, and ".". Assign sOutput to the innerHTML property of the solutions field. To get a reference to the solutions field, use document.getElementById("solutions"). output2ComplexSolutions() function ---------------------------------- Define a local variable, say sOutput, and assign it the string concatenation of: sSolutions1, complexSolutionRealPart, " + ", complexSolutionImaginaryPart, "i and ", complexSolutionRealPart, " - ", complexSolutionImaginaryPart, and "i.". Assign sOutput to the innerHTML property of the solutions field. To get a reference to the solutions field, use document.getElementById("solutions"). output2RealSolutions() function ------------------------------- Define a local variable, say sOutput, and assign it the string concatenation of: sSolutions1, realSolution1, " and ", realSolution2, ".". Assign sOutput to the innerHTML property of the solutions field. To get a reference to the solutions field, use document.getElementById("solutions"). reset() function ---------------- Change each fields value to an empty string. Here is the code to do this for field a: document.getElementById("a").value = ""; The id's of the other fields to reset are b, c, discriminant, and solutions. solve() function ---------------- You must first get the field values for the a, b, and c fields. Here is the code to get the value for the a field: a = document.getElementById("a").value; To validate the fields, you must call the validateFields() function. Make sure to pass it the parameters a, b, and c. If it returns false, use a return statement to immediately exit the solve() function. To calculate results, call the calculateSolutions() function. Make sure to pass it the parameters a, b, and c. To output your results, first call the outputDiscriminant() function. Then call the outputSolutions() function.

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

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions