Untitled

html 2 views Created:
 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8" />
  <title>Modos y generación de texto</title>
  <style>
    body { font-family: Arial, sans-serif; padding: 20px; }
    button { margin-right: 10px; padding: 8px 16px; }
    #modoActual { font-weight: bold; margin-left: 10px; }
    #resultado { margin-top: 20px; font-size: 24px; }
  </style>
</head>
<body>
  <h2>Generador de texto por modo</h2>

  <!-- Botón 1: cambiar entre Modo 1 y Modo 2 -->
  <button id="btnModo">Cambiar modo</button>
  <span>Modo actual: <span id="modoActual">1</span></span>

  <!-- Botón 2: generar texto según el modo -->
  <button id="btnGenerar">Generar texto</button>

  <div id="resultado"></div>

  <script>
    let modo = 1; // 1 o 2

    const btnModo = document.getElementById('btnModo');
    const btnGenerar = document.getElementById('btnGenerar');
    const modoActualSpan = document.getElementById('modoActual');
    const resultadoDiv = document.getElementById('resultado');

    // Cambiar entre Modo 1 y Modo 2
    btnModo.addEventListener('click', () => {
      modo = (modo === 1) ? 2 : 1;
      modoActualSpan.textContent = modo;
      resultadoDiv.textContent = ''; // opcional: limpiar resultado al cambiar modo
    });

    // Generar texto según el modo actual
    btnGenerar.addEventListener('click', () => {
      let textoGenerado = '';

      if (modo === 1) {
        // Modo 1: "I" o "D"
        const opcionesModo1 = ['I', 'D'];
        textoGenerado = opcionesModo1[Math.floor(Math.random() * opcionesModo1.length)];
      } else {
        // Modo 2: "RI", "RD", "AI" o "AD"
        const opcionesModo2 = ['RI', 'RD', 'AI', 'AD'];
        textoGenerado = opcionesModo2[Math.floor(Math.random() * opcionesModo2.length)];
      }

      resultadoDiv.textContent = textoGenerado;
    });
  </script>
</body>
</html>

Embed this paste

Please confirm