Advertisement
Javi

jQuery: Ejercicio

Jul 8th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         <script>   
  2.             function saludar(opts) {
  3.                 opts.mensaje = opts.mensaje || 'Hola';
  4.                 opts.repeticiones = opts.repeticiones || 1;
  5.                 opts.nivel = opts.nivel || 'log';
  6.                 opts.mayusculas = opts.mayusculas || false;
  7.                
  8.                 var output;
  9.                 if (opts.nombre == undefined) {
  10.                     output = opts.mensaje;
  11.                 } else {
  12.                     output = opts.nombre + ': ' + opts.mensaje;
  13.                 }
  14.                 if (opts.mayusculas == true) {
  15.                     output = output.toUpperCase();
  16.                 }
  17.                 for (var i=0; i < opts.repeticiones; i++) {
  18.                     console[opts.nivel](output);
  19.                 }
  20.            
  21.             }
  22.  
  23.             saludar({
  24.                 nombre : 'Alice',
  25.                 mensaje: 'ey ey ey!',
  26.                 repeticiones : 3,
  27.                 nivel : 'warn',
  28.                 mayusculas : true
  29.             });
  30.        
  31.         </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement