-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[MAD][WEB-PT0418][Alejandro González] #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,72 @@ | ||
| // Names and Input | ||
| //1 | ||
| let hacker1 = 'Alex'; | ||
| //2 | ||
| console.log("The driver's name is " + hacker1); | ||
| //3 | ||
| let hacker2 = prompt("What's your name"); | ||
| //4 | ||
| console.log("The navigator's name is " + hacker2); | ||
| //Conditionals | ||
| //5 | ||
| if (hacker1.length === hacker2.length) { | ||
| console.log('wow, you both got equally long names, ' + hacker1.length + ' characters'); | ||
| } else if (hacker1.length > hacker2.length) { | ||
| console.log('The Driver has the longest name, it has ' + hacker1.length + ' characters'); | ||
| } else if (hacker1.length < hacker2.length) { | ||
| console.log('Yo, navigator got the longest name, it has ' + hacker2.length + ' characters'); | ||
| } | ||
| //6 | ||
| console.log(hacker1.toUpperCase().split("").join(" ")) | ||
| //7 | ||
| console.log(hacker2.split("").reverse().join("")) | ||
|
|
||
| //8 | ||
|
|
||
| //Conditionals | ||
| var compareVariable = hacker1.localeCompare(hacker2); | ||
|
|
||
| if(compareVariable === 0){ | ||
| console.log("What?! You both got the same name?"); | ||
| }else if(compareVariable < 0){ | ||
| console.log("The driver's name goes first"); | ||
| }else if(compareVariable > 0){ | ||
| console.log("Yo, the navigator goes first definitely"); | ||
| } | ||
|
|
||
|
|
||
| //9 | ||
| let palindromeString = prompt("Write to know if it's a palindrome").toLowerCase(); | ||
|
|
||
| let normalString; | ||
|
|
||
| for (let i = 0; i < palindromeString.length; i++) { | ||
| if (palindromeString[i] !== " " && palindromeString[i] !== ",") { | ||
| normalString = normalString + palindromeString[i]; | ||
| } | ||
| } | ||
|
|
||
| let reverseString = normalString.split(" ").reverse().join(); | ||
|
|
||
| if (reverseString === normalString) { | ||
| console.log("It's a palindrome"); | ||
| } else { | ||
| console.log("It isn't a palindrome"); | ||
| } | ||
| // Lorem ipsum generator | ||
| //10 | ||
| let text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin metus est, gravida vel ullamcorper eget, imperdiet sit amet nulla. Nam faucibus, nisi et venenatis interdum, risus sapien viverra lectus, a laoreet lorem dolor consequat purus. Sed tempor sapien ac tellus tincidunt ullamcorper. Aliquam sollicitudin semper dolor eu tristique. Aliquam aliquam, sem ac lacinia volutpat, tellus felis pellentesque mauris, et consectetur nibh purus non nisi. Etiam faucibus tellus at turpis bibendum fermentum. Mauris nibh orci, tempus a massa at, laoreet faucibus justo. Morbi vitae suscipit nunc. Integer lacinia est et metus congue, id tincidunt leo viverra. Mauris volutpat non nisi nec dapibus. Donec lacinia mauris diam, convallis lacinia ipsum vestibulum sed. Phasellus vulputate et diam non ultricies. Duis sit amet ipsum vel lacus pulvinar facilisis eu sit amet lacus. Donec condimentum arcu erat, ut feugiat odio sodales eu. Pellentesque et gravida sem. In hac habitasse platea dictumst. Curabitur aliquam sed erat nec accumsan. Vivamus vestibulum pharetra est. Suspendisse ut lectus turpis. Nam pulvinar eros eu mauris viverra fringilla. Nunc urna risus, posuere id ipsum eget, finibus viverra urna. Cras sagittis est a libero gravida rhoncus. Vestibulum nec elit at enim dignissim vulputate id non augue. Phasellus sed accumsan erat, nec efficitur tellus. Aenean sem nulla, viverra a posuere vitae, tincidunt id est. Phasellus non porta diam, non pellentesque sapien. Fusce at felis eget leo porta semper. Pellentesque sit amet bibendum elit. Vivamus varius aliquam diam, in vestibulum sapien. Nunc convallis egestas erat, ac porttitor ligula molestie id." | ||
|
|
||
| let wordCount = 0; | ||
|
|
||
| for (let i = 0; i <= text.length; i++) { | ||
| if (text[i] === " ") { | ||
| wordCount++; | ||
| } | ||
| if (i === text.length) { | ||
| wordCount++; | ||
| } | ||
| } | ||
| console.log("Number of words: " + wordCount); | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No es mala idea ir contando los espacios para saber el número de palabras, pero si ya has utilizado la función split(), por qué no mejor: |
||
| let wordAux = text.split(" ").filter(item => item === 'et'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Está bien y es correcto, mi recomendación es que lo escribas de la siguiente manera por ahora: |
||
| console.log("Number of times the latin word et appears: " + wordAux.length) | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Y cómo harías para quitar las comillas de la última frase? porque la última es palíndrome si quitas las comillas y no evalúas las comillas, y es más, cómo quitarías cualquier símbolo que te pudiese llegar a poner para comprobar el suceso? (Lo que has hecho está bien, pero cómo lo pensarías para que te valiese para más casos?)
Tip: dale un repaso a cómo harías el ejercicio de localeCompare sin usar dicho método