-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava.js
More file actions
42 lines (32 loc) · 885 Bytes
/
java.js
File metadata and controls
42 lines (32 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const input = document.getElementById("codigo");
const lista = document.getElementById("lista");
input.addEventListener("keydown", function(event) {
if (event.key === "Enter") {
ejecutar();
}
});
function agregarLinea(texto) {
const li = document.createElement("li");
li.innerHTML = texto.replace(/\n/g, "<br>");
lista.appendChild(li);
}
function ejecutar() {
let codigo = input.value.trim();
if (codigo === "") return;
let salida = "";
const console = {
log: function(...texto) {
salida += texto.join(" ") + "\n";
}
};
try {
eval(codigo);
if (salida.trim() !== "") {
agregarLinea(salida.trim());
}
} catch (error) {
agregarLinea("Error: " + error.message);
}
input.value = "";
input.focus();
}