Skip to content

Instantly share code, notes, and snippets.

@solanoize
Created March 16, 2023 14:34
Show Gist options
  • Select an option

  • Save solanoize/73a7aa1fca1080bdd7ae345ddccdbf3b to your computer and use it in GitHub Desktop.

Select an option

Save solanoize/73a7aa1fca1080bdd7ae345ddccdbf3b to your computer and use it in GitHub Desktop.
Yuhu
var buttonEqual = document.querySelector(".equal");
var buttonDelete = document.querySelector(".delete");
var inputText = document.querySelector(".output");
var actions = document.querySelectorAll(".action");
var clear = document.querySelector(".clear");
let evals = [];
buttonEqual.addEventListener("click", function () {
let evaluate = inputText.value;
let result = Function(`return ${evaluate}`);
inputText.value = result();
});
buttonDelete.addEventListener("click", function () {
inputText.value = 0;
evals = [];
console.log(evals);
});
clear.addEventListener("click", function () {
evals.pop();
inputText.value = evals.join(" ");
});
for (var i = 0; i < actions.length; i++) {
actions[i].addEventListener("click", function (e) {
evals.push(e.target.innerHTML);
inputText.value = evals.join(" ");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment