js evaluator

This commit is contained in:
zyqunix 2025-04-15 21:18:46 +02:00
parent 4fb79a1d68
commit 776d988872
No known key found for this signature in database
GPG key ID: 134A8DEEA83B80E6
3 changed files with 86 additions and 0 deletions

19
js/index.js Normal file
View file

@ -0,0 +1,19 @@
const btn = document.getElementById('evaluate');
const input = document.getElementById('input');
const output = document.getElementById('output');
btn.addEventListener('click', function() {
output.innerText = '';
const originalLog = console.log;
console.log = function(...args) {
output.innerText += args.join(' ') + '\n';
originalLog.apply(console, args);
};
try {
let result = eval(input.value);
if (result !== undefined) output.innerText += result;
} catch (e) {
output.innerText += 'Error: ' + e.message;
}
console.log = originalLog;
});