JSFiddle - React, Tailwind, and code Playground

by Christopher McCulloh

HTML

<div id="console"></div>

JavaScript

var problems = [
    ".1+.1+.1+.1+.1+.1+.1",  //0.7  
    ".1*.1", //0.01
    ".1-.1", //0
    ".1/.1", //1
    ".1*.1+.1" //0.11
];
//a change
    


var hasPlusOrMinus = /[\+\-]+/;
var fullNumber = /(\d*\.?\d+|\d+)/g;
var $console = jQuery("#console");

for(var i=0,ii=problems.length; i < ii; i++){
    if(hasPlusOrMinus.test(problems[i])){
        var newProblem = problems[i].replace(fullNumber, "($1*1000000000)");

        //This eval needs to be replaced with something else, it causes problems for mixed calculations (those with both +\- and *\/). Need to do each +\- in the adjusted way, and then maybe eval the rest.
        var wrongAnswer = eval(newProblem);

        var rightAnswer = wrongAnswer/1000000000;
        $console.append(rightAnswer + "<br>");
        
    }else{
        var answer = eval(problems[i]);
        $console.append(answer + "<br>");
    }
}