Skip to content

Instantly share code, notes, and snippets.

@juancarloselorriaga
Last active May 1, 2019 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juancarloselorriaga/85955411b49e4e6f81212931559fec0c to your computer and use it in GitHub Desktop.
Save juancarloselorriaga/85955411b49e4e6f81212931559fec0c to your computer and use it in GitHub Desktop.
let hacker1 = 'David';
let hacker2 = window.prompt('Introduce el nombre del pasajero');
let hSize1 = hacker1.length;
let hSize2 = hacker2.length;
console.log(`The navigator's name is ${hacker2}`);
//Conditionals ------------**
if(hSize1 > hSize2){
console.log(`Driver has the longest name, it has ${hSize1} characters`);
}
else if (hSize2 > hSize1){
console.log(`Yo, navigator got the longest name, it has ${hSize2} characters`);
}
else{
console.log(`Wow, you both got equally long names, ${hSize2} characters!!`);
}
//Loops----------------**
//Punto 6.
let nombreDriverMayEspaciado='';
for(let i = 0; i < hSize1; i++){
nombreDriverMayEspaciado += hacker1[i].toUpperCase() + ' ';
}
console.log(nombreDriverMayEspaciado);
// Punto 7.
function reversa(texto){
let textoRev = '';
for(let i = texto.length - 1; i >= 0 ; i--){
textoRev += texto[i];
}
return textoRev;
}
let nombreNavRev = reversa(hacker2);
console.log(nombreNavRev);
// Punto 8.
let list = [hacker1, hacker2];
function ordenar(a, b){
if(a === b){
return 0;
}
else if(a > b){
return 1;
}
else{
return -1;
}
}
list.sort(ordenar);
console.log(list);
let primerNombre = list[0];
if(hacker1 === hacker2){
console.log(`What?! You both got the same name?`);
}
else if(primerNombre === hacker1){
console.log(`The driver's name goes first`);
}
else{
console.log(`Yo, the navigator goes first definitely`);
}
// Punto 9.
let posiblePalindromo = window.prompt('Ingresa un palíndromo');
let palindromoReversa = reversa(posiblePalindromo)
let palindromoSinEspaciosReversa = palindromoReversa.replace(/ /g, '');
let palindromoSinEspacios = posiblePalindromo.replace(/ /g, '');
if(palindromoSinEspacios.toLocaleLowerCase() === palindromoSinEspaciosReversa.toLocaleLowerCase()){
console.log(`Sí es un palíndromo`);
}
else{
console.log(`No es un palíndromo`);
}
// Punto 10.
let loremIpsum = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean non vulputate lorem. Nunc a feugiat ipsum, porttitor maximus quam. Nullam vehicula ut tortor quis faucibus. Suspendisse vitae sapien ac nisl vehicula vehicula. Mauris mattis eget lectus ac suscipit. Nullam sapien augue, hendrerit ut varius vel, dictum a leo. Integer dignissim in urna sed scelerisque. Proin iaculis dolor vitae nibh gravida tempor. Phasellus lobortis, enim id tempus tincidunt, ante magna cursus ante, et facilisis tortor ligula sit amet lacus. Nam commodo augue eu eleifend dictum. Sed eu pulvinar mauris. Maecenas cursus sagittis aliquam. Integer elementum dui venenatis sodales consequat. Cras non viverra metus. In in felis vel turpis convallis vulputate.
Aliquam a magna tincidunt, luctus eros viverra, pretium augue. Integer dictum tempus sem vitae pellentesque. Cras tempus risus sit amet enim consequat, consequat venenatis felis scelerisque. Duis feugiat tristique elit, ut blandit erat fringilla quis. Nam quis velit blandit, pharetra mauris efficitur, euismod turpis. Donec iaculis mollis mi vitae auctor. Sed rhoncus facilisis urna eget pellentesque. In posuere nibh sed sem accumsan, nec aliquam mauris placerat. Sed a tellus blandit, auctor mi tincidunt, faucibus ante.
Morbi magna sem, porttitor quis sem eu, porta suscipit orci. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Ut odio odio, dictum sed massa sed, cursus convallis ex. Ut id convallis lectus. Pellentesque at ante sit amet massa efficitur scelerisque. Phasellus eget velit sagittis, tristique nisi a, facilisis neque. Mauris sit amet lorem eu lectus fringilla faucibus.`;
let contador = 0;
for(let i = 0; i < loremIpsum.length; i++){
let caracter = loremIpsum[i];
if(caracter === ' '){
contador++;
}
}
console.log(`La cantidad de palabras en el texto es de ${contador}`);
@ta-web-mex
Copy link

Bien chicos!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment