mirror of
https://github.com/zyqunix/tools.git
synced 2025-07-06 06:20:30 +02:00
js evaluator
This commit is contained in:
parent
4fb79a1d68
commit
776d988872
3 changed files with 86 additions and 0 deletions
19
js/index.js
Normal file
19
js/index.js
Normal 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;
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue