JSFiddle - React, Tailwind, and code Playground

by Erik East

HTML

<body>
<h1>
Module 11
</h1>
<h2>
Assignment 9
</h2>
<h1>Finding the Ways</h1>
Select two nodes:
<br />From
<select id="from">
    <option value='A'>A</option>
    <option value='B'>B</option>
    <option value='C'>C</option>
    <option value='D'>D</option>
    <option value='E'>E</option>
    <option value='F' selected>F</option>
    <option value='G'>G</option>
</select>To
<select id="to">
    <option value='A'>A</option>
    <option value='B'>B</option>
    <option value='C' selected>C</option>
    <option value='D'>D</option>
    <option value='E'>E</option>
    <option value='F'>F</option>
    <option value='G'>G</option>
</select>
<input type="button" onclick="masterCalc();" value="Calculate" />
<br/>
<br/><span id="result"/>

<script>
    function Graph() {
        this.edges = {};

        this.addNode = function (label) {
            this.edges[label] = {};
        };

        this.addEdge = function (from, to, cost) {
            this.edges[from][to] = cost;
            this.edges[to][from] = cost;
        };

        this.calculatePaths = function (from, to, cost, paths) {
            // implement - this is designed for a recursive call
            // also if path is defined well - it will contain cost.
            paths.push(from);

            if(from == to){
                this.displayPath(paths.join(" "), cost)
            }
            for (var edge in this.edges[from]){
                if(paths.indexOf(edge) < 0){
                    console.log(edge);
                    var temp = cost+this.edges[from][edge];
                    this.calculatePaths(edge, to, temp, paths.slice());
                }
            }
        };

        this.displayPath = function (path, cost) {
            document.getElementById('result').innerHTML += path + ' -:- ' + cost + '<br/>';

        }

    }

    function masterCalc() {
        var from = document.getElementById('from').value;
        var to = document.getElementById('to').value;

       ...