Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="es">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="Arreglos.css">
    <title>Arreglos</title>
</head>

<body>
    <h1>Arreglos</h1>
    <div class="c1">
        <h2>Genera un tabla con números aleatorios</h2>
        <button id="aleatorios">Generar</button>
        <div class="c2">
            <h3>Tabla</h3>
            <table id="contenido"></table>
        </div>
        <h2>Ordena ó invierte la lista</h2>
        <button id="ordenar">Ordenar</button>
        <button id="invertir">Invertir</button>
        <h2>Agrega un elemnto al Principio ó al Final</h2>
        <input id="New" type="text" placeholder="Nuevo Elemento" required>
        <br>
        <button id="final">Agrega(Final)</button>
        <button id="ini">Agrega(Principio)</button>
    </div>
    
    <script src="Arreglos.js"></script>
</body>

</html>
              
            
!

CSS

              
                body{
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: rgb(46, 116, 173);
}

h1{
    color:#fdfffc;
    text-align: center;
    font-size: 40px;
    
}
h2, h3{
    color:#FF9F1C;
    font-size: 30px;
}

button{
    background-color:#b6b5b5;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
      font-size: 30px;
      color:rgb(46, 116, 173);
      width: 20%;
      height: 60px;
      border: 5px solid #FF9F1C;
}

input{
    padding:0px auto;
    width: 30%;
    height: .2%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    font-size: 26px;
    margin-bottom: .5%;
    text-align: center;
}
table{
    margin-top: 5%;
    margin-right: 40%;
    width: 60%;
    text-align: center;
}
td{
    background-color:#b6b5b5;
    color:rgb(46, 116, 173);
    font-size: 30px;
    border: 4px solid #FF9F1C;
}

#aleatorios{
    margin-left: 10%;
}

#ordenar{
    margin-left: 10%;
}
#New{
    margin-left: 15%;
}

#final{
    margin-left: 10%;
}
#ini{
    width: 30%;
}

.c1{
    float: left;
    width: 70%;

}

.c2{
    float: right;
    width: 25%;
}

@media screen 
and (max-width: 936px)
{
    .c1{

        float: none;
        display: inline-grid;
        width: 100%;

        grid-template-columns: repeat(1, 1fr);
        grid-template-rows: repeat(6,45px);
    
    }

    button{
        border-radius: 10px;
    }
    
    h1{
        font-size: 25px;
        text-align: center;
        margin-bottom: 10px;
        margin-top: 0px;
    }
    
    h2{
        visibility: hidden;
    }
     
    h3{
        font-size: 24px;
        margin-bottom: 0;
        margin-top: 10%;
    }

    .c2{
        grid-column: 1;
        grid-row: 1;
    }

    table
    {
        margin-right: none;
        width: 80%;
        
    }
    td{
        border-radius: 10px;
    }
    #aleatorios::after{
        content: " Tabla";
    }
    #aleatorios{
        grid-column: 1;
        grid-row: 1;
        width: 40%;
        font-size: 110%;
        margin-left: 50%;
        margin-right: none;
        margin-top: 4%;
    }
    
    #ordenar{
        grid-column: 1;
        grid-row: 2;
        width: 40%;
        font-size: 110%;
        margin-left: 50%;
        margin-right: none;
        margin-top: 10%;
        
    }

    #invertir{
        grid-column: 1;
        grid-row: 3;
        width: 40%;
        font-size: 110%;
        margin-left: 50%;
        margin-right: none;
        margin-top: 15%;
        
    }
    #New{
        grid-column: 1;
        grid-row: 4;
        width: 40%;
        height: 50%;
        margin-top: 22%;
        margin-left: 50%;
        margin-right: none;
        font-size: 110%;
    }
    
    #final{
        grid-column: 1;
        grid-row: 5;
        width: 40%;
        font-size: 110%;
        margin-left: 50%;
        margin-right: none;
        margin-top: 20%;
    }
    #ini{
        grid-column: 1;
        grid-row: 6;
        width: 40%;
        font-size: 110%;
        margin-left: 50%;
        margin-right: none;
        margin-top: 25%;
        font-size: 100%;
    }
}
              
            
!

JS

              
                 var arreglo = [];

document.querySelector('#aleatorios').addEventListener('click', generar);
document.querySelector('#aleatorios').addEventListener('click', llenartabla);

document.querySelector('#ordenar').addEventListener('click', ordena);
document.querySelector('#invertir').addEventListener('click', ordena2);

document.querySelector('#final').addEventListener('click', final);
document.querySelector('#ini').addEventListener('click', incio);

function llenartabla(){
    var cadena='';
    arreglo.forEach(function(elem){
        cadena+=`
        <tr>
            <td><strong>${elem}</strong></td>
        </tr>
        `;
    });

    document.querySelector('#contenido').innerHTML=cadena;
}
function generar() {
    for (var i = 0; i < 4; i++) {
        arreglo[i] = Math.floor(Math.random() * 99 + 1);
    }
}

function imprimir(elemento) {
    console.log(elemento)
}


function ordena(){
    arreglo.sort(comparaNum);
    llenartabla();
}

function ordena2(){
    arreglo.reverse(comparaNum);
    llenartabla();
}

function comparaNum(a, b) {
    if (a < b) return -1;
    if (a > b) return 1;
    if (a == b) return 0;
}

function final(){
    arreglo.push(document.getElementById('New').value);
    llenartabla();
}
function incio(){
    arreglo.unshift(document.getElementById('New').value);
    llenartabla();
}
              
            
!
999px

Console