css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="wrapper">
  <h1 class="cof_h">¿A ti cómo te gusta el café?</h1>
  <p id="resultado"></p>
  <button id="btn-generate">Genera el tuyo</button>
</div>

            
          
!
            
              // Variables
$color-cafe-dark: #4D423E;
$color-cafe-medium: #AD8461;
$color-cafe-light: #E7CDB1;
$color-light: #ffffff;
$border-radius: 25px;
  
body {
  background-color: $color-cafe-dark;
  font-family: 'Lato', sans-serif;
}

.wrapper {
  background-color: $color-cafe-medium;
  border-radius: $border-radius;
  margin: 2em auto 3em;
  padding: 2em 4em 4em;
  width: 60%;
}

.cof_h {
  color: $color-light;
  font-size: 3em;
}

button {
  background-color: $color-cafe-light;
  border: 2px solid $color-cafe-light;
  border-radius: $border-radius;
  color: $color-cafe-dark;
  cursor: pointer;
  font-size: 1em;
  font-weight: bold;
  outline: 0;
  padding: 1em 1.5em;
  transition: 0.4s border-color;
}
button:hover { border-color: $color-cafe-dark; }

#resultado {
  color: $color-light;
  font-size: 2em;
  font-style: italic;
}
            
          
!
            
              // Variables
var boton = document.getElementById( 'btn-generate' );
var resultado = document.getElementById( 'resultado' );

// Completo los array con las posibilidades básicas de café en España
var tipos = ['', 'descafeinado']; // El elemento vacío del array de tiposcorresponde al café con cafeína, que, por defecto, no se suele indicar.
var origen = ['', 'de sobre']; // El elemento vacío del array de origen coresponde al café de máquina que por defecto no se suele indicar
var adicional = ['solo', 'con leche', 'con leche desnatada', 'con leche de soja'];
var temp_adicional = ['', 'fría', 'templada', 'caliente']; // Tenemos un elemento vacío para dar la posibilidad de agregarle hielo.
var contenedor = ['', 'en vaso']; // El elemento vacío del array de contenedor corresponde a una taza que, por defecto, no se suele indicar.
var hielo = ['', 'con hielo']; // El elemento vacío del array hielo corresponde a 'sin hielo' que, por defecto, no se suele indicar.
var edulcorante = ['', 'con azúcar moreno', 'con sacarina', 'con stevia'] // El elemento vacío del array edulocorante corresponde a 'azúcar' que, por defecto, no se suele indicar.

// Agregar Listener al botón
boton.addEventListener( 'click', function(){ generar_cafe(); } );


/* 
* Función que genera todas las posibilidades
* españolas de café
*/
function generar_cafe() {
  
  var cafe = [];
  var r_tipos = tipos[random( tipos.length )];
  var r_origen = origen[random( origen.length )];
  var r_adicional = adicional[random( adicional.length )];
  var r_temp_adicional = temp_adicional[random( temp_adicional.length )];
  var r_contenedor = contenedor[random( contenedor.length )];
  var r_hielo = hielo[random( hielo.length )];
  var r_edulcorante = edulcorante[random( edulcorante.length )];
  
  // Solo agrego al las opciones que no estén vacías
  if( "" !== r_tipos ) cafe.push( r_tipos );
  if( "" !== r_origen ) cafe.push( r_origen );
  
  cafe.push( r_adicional );
  if( "solo" !== r_adicional ) {
    if( "" !== r_temp_adicional ) cafe.push( r_temp_adicional );
  }
  
  if( "" !== r_contenedor ) cafe.push( r_contenedor );
  
  if( "" === r_temp_adicional && "" !== r_hielo ) cafe.push( r_hielo );
  
  if( "" !== r_edulcorante ) cafe.push( r_edulcorante );
  
  // Devuelvo la combinación del café ¡Que lo disfrutes!
  console.log(cafe.join(", "));
  resultado.innerHTML = "\"A mi me gusta " + cafe.join(", ") + ".\"";
  
}



/*
* Función que devuelve un número aleatorio
* @param numero_maximo    número máximo posible a devolver
* @return int             el número aleatorio generado
*/
function random( numero_maximo ) {
  return Math.floor( Math.random() * numero_maximo );
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console