Skip to content

Commit a694d1a

Browse files
Update script.js
1 parent 6235eab commit a694d1a

1 file changed

Lines changed: 21 additions & 32 deletions

File tree

script.js

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,37 @@
1-
// CONTROLE DE TEMA
2-
const themeButton = document.getElementById('theme-button');
3-
const storedTheme = localStorage.getItem('theme') || 'dark';
4-
5-
document.documentElement.setAttribute('data-theme', storedTheme);
6-
7-
themeButton.addEventListener('click', () => {
8-
let currentTheme = document.documentElement.getAttribute('data-theme');
9-
let newTheme = currentTheme === 'light' ? 'dark' : 'light';
10-
11-
document.documentElement.setAttribute('data-theme', newTheme);
12-
localStorage.setItem('theme', newTheme);
1+
// TEMA CLARO/ESCURO
2+
const btn = document.getElementById('theme-button');
3+
btn.addEventListener('click', () => {
4+
const doc = document.documentElement;
5+
const isLight = doc.getAttribute('data-theme') === 'light';
6+
doc.setAttribute('data-theme', isLight ? 'dark' : 'light');
137
});
148

159
// SISTEMA DE PRÁTICAS
16-
const aulasConteudo = {
17-
1: { titulo: "Variáveis", codigo: "let aluno = 'Bernardo';\nconsole.log('Bem-vindo, ' + aluno);" },
18-
2: { titulo: "Funções", codigo: "function tchau(){ return 'Até logo!'; }\nconsole.log(tchau());" }
10+
const conteudo = {
11+
1: { t: "Variáveis", c: "let nome = 'Bernardo';\nconsole.log('Olá, ' + nome);" },
12+
2: { t: "Funções", c: "function soma(a,b){ return a+b; }\nconsole.log(soma(5,10));" }
1913
};
2014

2115
function verAula(id) {
2216
const area = document.getElementById('tutorial-texto');
23-
const aula = aulasConteudo[id];
24-
if(!area) return;
25-
17+
const aula = conteudo[id];
2618
area.innerHTML = `
27-
<div class="card" style="background: var(--bg-color); color: var(--text-color);">
28-
<h2 style="color: var(--accent)">Editando: ${aula.titulo}</h2>
29-
<textarea id="codigo-editor">${aula.codigo}</textarea>
30-
<button onclick="executar()" class="btn-primary">RODAR CÓDIGO</button>
31-
<div id="console-output">> Resultado aparecerá aqui...</div>
19+
<div class="card" style="margin-bottom:20px;">
20+
<h3>Praticando: ${aula.t}</h3>
21+
<textarea id="codigo-editor">${aula.c}</textarea>
22+
<button onclick="rodar()" class="btn-primary" style="margin-top:10px;">Executar</button>
23+
<div id="console-output">> Resultado...</div>
3224
</div>`;
33-
window.scrollTo({top: 0, behavior: 'smooth'});
3425
}
3526

36-
function executar() {
37-
const cod = document.getElementById('codigo-editor').value;
27+
function rodar() {
28+
const code = document.getElementById('codigo-editor').value;
3829
const out = document.getElementById('console-output');
3930
out.innerHTML = "";
4031
try {
41-
const log = console.log;
32+
const originalLog = console.log;
4233
console.log = (m) => { out.innerHTML += "> " + m + "<br>"; };
43-
eval(cod);
44-
console.log = log;
45-
} catch (e) {
46-
out.innerHTML = "<span style='color:red;'>Erro: " + e.message + "</span>";
47-
}
34+
eval(code);
35+
console.log = originalLog;
36+
} catch(e) { out.innerHTML = "Erro: " + e.message; }
4837
}

0 commit comments

Comments
 (0)