JSFiddle - React, Tailwind, and code Playground

by Neil Daley

HTML

Quadratic Equation Calculator<br /><br />
y = ax<sup>3</sup> + bx<sup>2</sup> + cx + d<br /><br />

    Input a <input type="text" id="a" size="5" value ="2"/><br />
    Input b <input type="text" id="b" size="5" value ="6"/><br />
    Input c <input type="text" id="c" size="5" value ="1"/><br />
    X Min<input type="text" id="xmin" size="-10" value ="5"/><br />
    X Max<input type="text" id="xmax" size="10" value ="5"/><br />
<br /><br />

<input type="button" value="Calculate" id="calculate" />
<input type="button" value="Plot" id="plot" />

<br /><br />
<p id="output"> </p>

<div id="container" style="min-width: 480px; height: 400px; margin: 0 auto"></div>

JavaScript

// Global variables
var a = 0;
var b = 0;
var c = 0;
var n = 0;
var x = new Array();
var y = new Array(); 
var v = new Array();

function calculateY(a, b, c, x) {
    return a * x * x + b * x + c;
}

function calculate() {
    a = Number($('#a').val());
    b = Number($('#b').val());
    c = Number($('#c').val());
    var xmin = Number($('#xmin').val());
    var xmax = Number($('#xmax').val());
    var xt = 0;
    
    
    var i = 0;
    for (xt = xmin; xt <= xmax; xt++) {
        x[i] = xt;
        y[i] = calculateY(a, b, c, xt);
        v[i] = [x[i], y[i]];
        i++;
    }
    n = i - 1;
    
}

function displayValues()
{
   var s = "";
    
    s = "Y = " + a + " x<sup>2</sup> + ";
    s+= b + " x + " + c + "<br/><br/>";
    
    for (var i = 0; i <= n; i++)
    {
        s += " X = " + x[i] + " Y = " + y[i] + "<br/>";       
    }
    
    output.innerHTML = s;
}

function plotValues()
{
   calculate();
   chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'line',
                marginRight: 130,
                marginBottom: 25
            },
            title: {
                text: 'Quadratic Equation',
                x: -20 //center
            },
            xAxis: {
                title: {
                    text: 'X'
                }
            },
            yAxis: {
                title: {
                    text: 'Y'
                }   
            }, 
       
       plotOptions: {
                scatter: {
                    marker: {
                        radius: 5,
                        states: {
                            hover: {
                                enabled: true,
                                lineColor: 'rgb(100,100,100)'
                            }
                        }
                    },
                    states: {
                        hover: {
                            marker: {
                                enabled: false
   ...