| 
8 | 8 | 
 
  | 
9 | 9 | ( () => {  | 
10 | 10 |  var file = `{  | 
11 |  | - "1": {  | 
12 |  | - "orden": "1.1",  | 
13 |  | - "titulo": "Got 15 minutes and want to learn Git?",  | 
14 |  | - "tareas": [  | 
15 |  | - "Git allows groups of people to work on the same documents (often code) at the same time, and without stepping on each other's toes. It's a distributed version control system.",   | 
16 |  | - "Our terminal prompt below is currently in a directory we decided to name 'octobox'. To initialize a Git repository here, type the following command:"  | 
17 |  | - ],  | 
18 |  | - "comando": "git init",  | 
19 |  | - "errorMessages": ["fatal: Not a git repository (or any of the parent directories): .git"],  | 
20 |  | - "error": "Did not create a Git repo",  | 
21 |  | - "successMessages": ["Initialized empty Git repository in /.git/"],  | 
22 |  | - "success": "Success!",  | 
23 |  | - "repoStatus": "Empty"  | 
 | 11 | + "config": {  | 
 | 12 | + "errorComando": "comand not found"  | 
 | 13 | + },  | 
 | 14 | + "lecciones": {  | 
 | 15 | + "1": {  | 
 | 16 | + "orden": "1.1",  | 
 | 17 | + "titulo": "Got 15 minutes and want to learn Git?",  | 
 | 18 | + "tareas": [  | 
 | 19 | + "Git allows groups of people to work on the same documents (often code) at the same time, and without stepping on each other's toes. It's a distributed version control system.",   | 
 | 20 | + "Our terminal prompt below is currently in a directory we decided to name 'octobox'. To initialize a Git repository here, type the following command:"  | 
 | 21 | + ],  | 
 | 22 | + "comando": "git init",  | 
 | 23 | + "errorMessages": ["fatal: Not a git repository (or any of the parent directories): .git"],  | 
 | 24 | + "alert": "Did not create a Git repo",  | 
 | 25 | + "successMessages": ["Initialized empty Git repository in /.git/"],  | 
 | 26 | + "repoStatus": "Empty"  | 
 | 27 | + }  | 
24 | 28 |  }  | 
25 | 29 |  }`;  | 
26 |  | - var lecciones = JSON.parse(file);  | 
 | 30 | + var lecciones = JSON.parse(file).lecciones;  | 
 | 31 | + var config = JSON.parse(file).config;  | 
27 | 32 | 
 
  | 
28 | 33 |  var leccionActual = 0;  | 
29 | 34 | 
 
  | 
 | 
59 | 64 |  function mostrarResultado(passOrFail) {  | 
60 | 65 |  // Mostrar resultado  | 
61 | 66 |  if (passOrFail == 'pass') {  | 
 | 67 | + // PASSED  | 
62 | 68 |  for (var i = 0; i < lecciones[leccionActual].successMessages.length; i++) {  | 
63 | 69 |  let parrafo = crearParrafo(lecciones[leccionActual].successMessages[i]);   | 
64 |  | - consoleArea.lastElementChild.appendChild(parrafo);  | 
 | 70 | + consoleArea.appendChild(parrafo);  | 
65 | 71 |  }  | 
66 |  | - let parrafo = crearParrafo(lecciones[leccionActual].success);   | 
 | 72 | + let parrafo = crearParrafo("Success!");   | 
 | 73 | + console.log(parrafo);   | 
67 | 74 |  parrafo.classList.add('success');   | 
68 |  | - consoleArea.lastElementChild.appendChild(parrafo);  | 
 | 75 | + consoleArea.appendChild(parrafo);  | 
69 | 76 |  // Siguiente leccion  | 
70 | 77 |  leccionActual++;  | 
71 | 78 |  } else {  | 
72 |  | - for (var i = 0; i < lecciones[leccionActual].errorMessages.length; i++) {  | 
73 |  | - let parrafo = crearParrafo(lecciones[leccionActual].errorMessages[i]);   | 
74 |  | - consoleArea.lastElementChild.appendChild(parrafo);  | 
 | 79 | + // FAILED  | 
 | 80 | + if (RegExp("(git)", "g").test(textarea.value.trim())) {  | 
 | 81 | + for (var i = 0; i < lecciones[leccionActual].errorMessages.length; i++) {  | 
 | 82 | + let parrafo = crearParrafo(lecciones[leccionActual].errorMessages[i]);   | 
 | 83 | + consoleArea.appendChild(parrafo);  | 
 | 84 | + }  | 
 | 85 | + } else {  | 
 | 86 | + let comandError = crearParrafo(textarea.value + ": " + config.errorComando);   | 
 | 87 | + consoleArea.lastElementChild.appendChild(comandError);  | 
 | 88 | + console.log(RegExp("(git)", "g").test(textarea.value.trim()));  | 
75 | 89 |  }  | 
76 |  | - let parrafo = crearParrafo(lecciones[leccionActual].error);  | 
 | 90 | + // Red error message  | 
 | 91 | + let parrafo = crearParrafo(lecciones[leccionActual].alert);  | 
77 | 92 |  parrafo.classList.add('error');   | 
78 |  | - consoleArea.lastElementChild.appendChild(parrafo);  | 
 | 93 | + consoleArea.appendChild(parrafo);  | 
79 | 94 |  }  | 
 | 95 | + // let parrafoVacio = document.createElement("p");  | 
 | 96 | + // parrafoVacio.classList.add('empty-p');  | 
 | 97 | + // consoleArea.appendChild(parrafoVacio);  | 
80 | 98 |  }  | 
81 | 99 | 
 
  | 
82 | 100 |  function cambiarLineaActual(passOrFail) {  | 
83 | 101 |  let lineaActual = document.querySelector('.current-line');  | 
84 | 102 |  let parrafo = crearParrafo("$ " + textarea.value);  | 
85 |  | - let parrafoVacio = document.createElement("p");  | 
86 |  | - parrafoVacio.classList.add('empty-p');  | 
87 |  | - parrafoVacio.classList.innerHTML = " ";  | 
88 |  | - lineaActual.innerHTML = "";  | 
89 |  | - | 
90 |  | - lineaActual.appendChild(parrafo);  | 
91 |  | - lineaActual.appendChild(parrafoVacio);  | 
92 |  | - lineaActual.classList.remove('current-line');  | 
93 |  | - lineaActual.classList.add('line');  | 
94 |  | - | 
95 |  | - mostrarResultado(passOrFail);  | 
96 |  | - | 
97 |  | - let div = document.createElement("div");  | 
98 |  | - consoleArea.appendChild(div);  | 
99 |  | - | 
100 |  | - consoleArea.lastElementChild.classList.add('current-line');  | 
101 |  | - lineaActual = document.querySelector('.current-line');  | 
102 |  | - lineaActual.innerHTML = '<span>$ </span><textarea id="console-input"></textarea>';  | 
103 |  | - // Ayudar listener para el textarea  | 
104 |  | - addTextareaListener();  | 
105 |  | - textarea.value = "";  | 
106 |  | - textarea.focus();  | 
 | 103 | + parrafo.style.marginTop = "15px";  | 
 | 104 | + parrafo.style.marginBottom = "15px";  | 
 | 105 | + // let parrafoVacio = document.createElement("p");  | 
 | 106 | + // parrafoVacio.classList.add('empty-p');  | 
 | 107 | + consoleArea.removeChild(lineaActual);  | 
 | 108 | + | 
 | 109 | + consoleArea.appendChild(parrafo);  | 
 | 110 | + // consoleArea.appendChild(parrafoVacio);  | 
 | 111 | + consoleArea.classList.remove('current-line');  | 
 | 112 | + // lineaActual.classList.add('line');  | 
 | 113 | + | 
 | 114 | + setTimeout(function() {  | 
 | 115 | + mostrarResultado(passOrFail);  | 
 | 116 | + let div = document.createElement("div");  | 
 | 117 | + consoleArea.appendChild(div);  | 
 | 118 | + | 
 | 119 | + consoleArea.lastElementChild.classList.add('current-line');  | 
 | 120 | + consoleArea.lastElementChild.style.marginTop = "15px";  | 
 | 121 | + lineaActual = document.querySelector('.current-line');  | 
 | 122 | + lineaActual.innerHTML = '<span>$ </span><textarea id="console-input" spellcheck="false"></textarea>';  | 
 | 123 | + // Ayudar listener para el textarea  | 
 | 124 | + addTextareaListener();  | 
 | 125 | + textarea.value = "";  | 
 | 126 | + textarea.focus();  | 
 | 127 | + }, 2000);  | 
 | 128 | + | 
107 | 129 |  }  | 
108 | 130 | 
 
  | 
109 | 131 |  function crearParrafo(texto) {  | 
 | 
148 | 170 |  });  | 
149 | 171 |  }  | 
150 | 172 | 
 
  | 
 | 173 | + document.querySelector('.comando').addEventListener('click', () => {  | 
 | 174 | + textarea.classList.add("typed");  | 
 | 175 | + textarea.value = lecciones[leccionActual].comando;  | 
 | 176 | + });  | 
 | 177 | + | 
151 | 178 |  // Actualizar instrucciones al cargar  | 
152 | 179 |  actualizarInstrucciones();  | 
153 | 180 |  // Ayudar listener para el textarea al cargar  | 
 | 
0 commit comments