Hello I am currently making an calculator for my class that is pretty easy to use once you install the mathjs library, my goal is to make a calculator that takes the input and evaluates the problem stated. My problem is that I can't seem to make an if statement that recognizes that it cant evaluate a function like "2x + 3" which should leave it undefined because of the x and I just want it to state "Not Defined" because of the uncaught error and just evaluate if it is a straight forward problem like 2 + 2. I am just trying to make the value show using the function with textcontent and when the input shows an actual function then it will solve and when it is undefined like 2x + 3 than it is to show "Not defined).
var input = document.querySelector('#value-input').value;
var value = document.querySelector('#value');
var eval = math.eval(input);
if (value.textContent === undefined) {
value.textContent = "Not defined"
} else {
value.textContent = eval
}
})})
Aucun commentaire:
Enregistrer un commentaire