-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
19 lines (17 loc) · 739 Bytes
/
script.js
File metadata and controls
19 lines (17 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
window.onload = () => {
const [input, output] = document.querySelectorAll('.codemirror-textarea');
const [run, clear] = document.querySelectorAll('button');
const editor = CodeMirror.fromTextArea(input, { lineNumbers: true });
const shell = CodeMirror.fromTextArea(output, { lineNumbers: false });
run.addEventListener('click', () => {
const codeToRun = editor.getValue();
try{
shell.replaceRange('$ ' + eval(`${codeToRun}`) + '\n', CodeMirror.Pos(shell.lastLine()));
} catch(e){
shell.replaceRange('$ ' + e + '\n', CodeMirror.Pos(shell.lastLine()));
}
});
clear.addEventListener('click', () => {
shell.setValue('')
});
}